-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
133 lines (111 loc) · 5.16 KB
/
script.js
File metadata and controls
133 lines (111 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Theme toggle
const toggle = document.getElementById('themeToggle');
const body = document.body;
let currentTheme = localStorage.getItem('theme') || 'light';
body.setAttribute('data-theme', currentTheme);
toggle.innerHTML = currentTheme === 'dark' ? '<i class="fas fa-sun"></i>' : '<i class="fas fa-moon"></i>';
toggle.addEventListener('click', () => {
currentTheme = currentTheme === 'dark' ? 'light' : 'dark';
body.setAttribute('data-theme', currentTheme);
localStorage.setItem('theme', currentTheme);
toggle.innerHTML = currentTheme === 'dark' ? '<i class="fas fa-sun"></i>' : '<i class="fas fa-moon"></i>';
});
// Modal logic (warning + tutorial)
const warningModal = document.getElementById('warningModal');
const tutorialModal = document.getElementById('tutorialModal');
function closeWarningModal() {
warningModal.classList.remove('show');
if (document.getElementById('dontShowWarning').checked) localStorage.setItem('hideWarning', 'true');
if (!localStorage.getItem('hideTutorial')) setTimeout(() => tutorialModal.classList.add('show'), 300);
}
function closeTutorialModal() {
tutorialModal.classList.remove('show');
if (document.getElementById('dontShowTutorial').checked) localStorage.setItem('hideTutorial', 'true');
}
document.getElementById('closeWarning').onclick = closeWarningModal;
document.getElementById('closeTutorial').onclick = closeTutorialModal;
if (!localStorage.getItem('hideWarning')) {
setTimeout(() => warningModal.classList.add('show'), 800);
} else if (!localStorage.getItem('hideTutorial')) {
setTimeout(() => tutorialModal.classList.add('show'), 800);
}
// Core date logic
const endDateInput = document.getElementById('endDate');
const fullDateDisplay = document.getElementById('fullDateDisplay');
const daysDisplay = document.getElementById('daysDisplay');
const monthsDisplay = document.getElementById('monthsDisplay');
const yearsDisplay = document.getElementById('yearsDisplay');
function getOrdinalSuffix(day) {
if (day % 10 === 1 && day % 100 !== 11) return 'st';
if (day % 10 === 2 && day % 100 !== 12) return 'nd';
if (day % 10 === 3 && day % 100 !== 13) return 'rd';
return 'th';
}
function generateDates() {
const endDate = new Date(endDateInput.value);
const today = new Date();
today.setHours(0,0,0,0);
endDate.setHours(0,0,0,0);
if (!endDateInput.value || isNaN(endDate)) return { error: "Please select a date." };
if (endDate < today) return { error: "End date must be in the future." };
const full = [], days = [], months = [], years = [];
let current = new Date(today);
while (current <= endDate) {
const dayOfWeek = current.toLocaleString('default', { weekday: 'long' });
const month = current.toLocaleString('default', { month: 'long' });
const dayNum = current.getDate();
const year = current.getFullYear();
const ordinal = getOrdinalSuffix(dayNum);
full.push(`${dayOfWeek}, ${month} ${dayNum}${ordinal}, ${year}`);
days.push(dayNum);
if (current.getDate() === 1) {
months.push(`${current.getMonth() + 1}. ${month}`);
}
if (current.getMonth() === 0 && current.getDate() === 1) {
years.push(year);
}
current.setDate(current.getDate() + 1);
}
return { full: full.join('\n'), days: days.join('\n'), months: months.join('\n'), years: years.join('\n') };
}
function showResult(type) {
const data = generateDates();
const target = { full: fullDateDisplay, days: daysDisplay, months: monthsDisplay, years: yearsDisplay }[type];
if (data.error) {
target.textContent = data.error;
} else {
target.textContent = data[type] || "No data for this view.";
}
}
function downloadResult(type, filename) {
const data = generateDates();
if (data.error) return alert(data.error);
const blob = new Blob([data[type]], { type: 'text/plain' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = filename;
link.click();
}
// Button listeners
document.getElementById('showFullDateBtn').onclick = () => showResult('full');
document.getElementById('showDaysBtn').onclick = () => showResult('days');
document.getElementById('showMonthsBtn').onclick = () => showResult('months');
document.getElementById('showYearsBtn').onclick = () => showResult('years');
document.getElementById('downloadFullDateBtn').onclick = () => downloadResult('full', 'full_dates.txt');
document.getElementById('downloadDaysBtn').onclick = () => downloadResult('days', 'days_only.txt');
document.getElementById('downloadMonthsBtn').onclick = () => downloadResult('months', 'months_list.txt');
document.getElementById('downloadYearsBtn').onclick = () => downloadResult('years', 'years_list.txt');
// Copy helper
function copyToClipboard(elementId) {
const el = document.getElementById(elementId);
const text = el.textContent.trim();
if (!text || text.includes("Please") || text.includes("must")) {
alert("Nothing useful to copy yet.");
return;
}
navigator.clipboard.writeText(text).then(() => {
alert("Copied to clipboard!");
}).catch(() => {
alert("Copy failed — try selecting the text manually.");
});
}