-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc2.html
More file actions
311 lines (264 loc) · 10.7 KB
/
c2.html
File metadata and controls
311 lines (264 loc) · 10.7 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!DOCTYPE html>
<html>
<head>
<title>Monthly Calendar</title>
<meta charset="UTF-8">
<style>
.calendar-container {
max-width: 300px; /* Increased size */
margin: 20px auto;
font-family: Arial, sans-serif;
font-size: 14px; /* Increased size */
}
.controls {
margin-bottom: 10px;
display: flex;
gap: 5px;
align-items: center;
}
select {
font-size: 14px;
padding: 3px;
}
.month-display {
font-weight: bold;
font-size: 1.2em;
margin-bottom: 5px;
text-align: center;
}
.calendar-grid {
display: grid;
grid-template-columns: repeat(7, 1fr) 45px; /* Only right week column */
gap: 2px;
}
.calendar-header {
padding: 5px;
text-align: center;
font-weight: bold;
border: 1px solid #ccc;
font-size: 13px;
}
.calendar-day {
padding: 5px;
text-align: center;
border: 1px solid #ccc;
min-height: 20px;
line-height: 20px;
}
.past-day {
text-decoration: line-through;
color: #999;
}
.other-month {
color: #ccc;
}
.today {
font-weight: bold;
}
.embed-button {
padding: 6px 12px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 3px;
cursor: pointer;
margin: 5px;
font-size: 14px;
}
.arrow {
font-size: 22px;
cursor: pointer;
user-select: none;
padding: 0 8px;
}
.hidden {
display: none;
}
.week-display {
font-size: 12px;
text-align: center;
padding: 5px;
border: 1px solid #ccc;
min-height: 20px;
line-height: 20px;
}
.arrow {
font-size: 22px;
cursor: pointer;
user-select: none;
position: absolute;
top: 100px;
transform: translateY(-50%);
padding: 10px;
border-radius: 50%;
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
}
.prev {
left: -30px;
}
.next {
right: -32px;
}
/* Update calendar controls style */
#calendar-controls {
position: relative;
height: 0;
margin: 0;
}
.month-display {
text-align: center;
margin: 10px 0;
}
</style>
</head>
<body>
<div class="calendar-container">
<div id="initial-controls" class="controls">
<select id="startDay">
<option value="0">Start from Sunday</option>
<option value="1">Start from Monday</option>
</select>
<select id="background">
<option value="#ffffff">White Grid</option>
<option value="#f0f8ff">Light Blue Grid</option>
<option value="#f5f5dc">Beige Grid</option>
<option value="#e6ffe6">Light Green Grid</option>
<option value="#e6e6fa">Light Purple Grid</option>
</select>
<button id="embedButton" class="embed-button">Embed</button>
</div>
<div class="month-display"></div>
<div id="calendar-controls" class="controls hidden">
<span class="arrow prev"><</span>
<div class="month-display"></div>
<span class="arrow next">></span>
</div>
<div id="calendar"></div>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const calendar = document.getElementById("calendar");
const startDaySelect = document.getElementById("startDay");
const backgroundSelect = document.getElementById("background");
const embedButton = document.getElementById("embedButton");
const initialControls = document.getElementById("initial-controls");
const calendarControls = document.getElementById("calendar-controls");
const monthDisplay = document.querySelector(".month-display");
let currentMonth = new Date().getMonth();
let currentYear = new Date().getFullYear();
function getWeekNumber(date) {
const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
const pastDaysOfYear = (date - firstDayOfYear) / 86400000;
return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7);
}
function applyGridColor() {
const gridColor = backgroundSelect.value;
document.querySelectorAll('.calendar-day, .calendar-header, .week-display').forEach(el => {
el.style.backgroundColor = gridColor;
});
}
function generateCalendar() {
const startDay = parseInt(startDaySelect.value);
const today = new Date();
const date = new Date(currentYear, currentMonth, 1);
const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
monthDisplay.textContent = `${monthNames[currentMonth]} ${currentYear}`;
let calendarHTML = '<div class="calendar-grid">';
// Add day headers
const days = startDay === 0
? ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
days.forEach(day => {
calendarHTML += `<div class="calendar-header">${day}</div>`;
});
// Add "Week" header
calendarHTML += '<div class="calendar-header">Week</div>';
let firstDay = date.getDay();
if (startDay === 1) {
firstDay = firstDay === 0 ? 6 : firstDay - 1;
}
const lastDay = new Date(currentYear, currentMonth + 1, 0).getDate();
const prevMonthLastDay = new Date(currentYear, currentMonth, 0).getDate();
let dayCount = 1;
let nextMonthDay = 1;
const totalDays = firstDay + lastDay;
const totalRows = Math.ceil(totalDays / 7);
for (let row = 0; row < totalRows; row++) {
for (let col = 0; col < 7; col++) {
const dayPosition = row * 7 + col;
const dayIndex = dayPosition - firstDay;
if (dayIndex < 0) {
const prevDay = prevMonthLastDay + dayIndex + 1;
calendarHTML += `<div class="calendar-day other-month">${prevDay}</div>`;
} else if (dayIndex >= lastDay) {
calendarHTML += `<div class="calendar-day other-month">${nextMonthDay++}</div>`;
} else {
const currentDate = dayIndex + 1;
const isToday = currentDate === today.getDate() &&
currentMonth === today.getMonth() &&
currentYear === today.getFullYear();
const isPast = new Date(currentYear, currentMonth, currentDate) < new Date(today.getFullYear(), today.getMonth(), today.getDate());
calendarHTML += `<div class="calendar-day${isToday ? ' today' : ''}${isPast ? ' past-day' : ''}">${currentDate}</div>`;
}
}
// Add week number
const weekDate = new Date(currentYear, currentMonth, dayCount - firstDay + (row * 7));
const weekNum = getWeekNumber(weekDate);
calendarHTML += `<div class="week-display">${weekNum}</div>`;
}
calendarHTML += '</div>';
calendar.innerHTML = calendarHTML;
applyGridColor();
}
function changeMonth(delta) {
currentMonth += delta;
if (currentMonth > 11) {
currentMonth = 0;
currentYear++;
} else if (currentMonth < 0) {
currentMonth = 11;
currentYear--;
}
generateCalendar();
updateURL();
}
function updateURL() {
const url = new URL(window.location.href);
url.searchParams.set('startDay', startDaySelect.value);
url.searchParams.set('background', backgroundSelect.value);
// url.searchParams.set('month', currentMonth);
// url.searchParams.set('year', currentYear);
window.history.pushState({}, '', url.toString());
}
embedButton.addEventListener("click", () => {
const embedUrl = window.location.href;
navigator.clipboard.writeText(embedUrl).then(() => {
initialControls.classList.add("hidden");
calendarControls.classList.remove("hidden");
updateURL();
});
});
// Check URL parameters on load
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('startDay') && urlParams.has('background')) {
startDaySelect.value = urlParams.get('startDay');
backgroundSelect.value = urlParams.get('background');
// currentMonth = parseInt(urlParams.get('month')) || currentMonth;
// currentYear = parseInt(urlParams.get('year')) || currentYear;
initialControls.classList.add("hidden");
calendarControls.classList.remove("hidden");
}
document.querySelector(".prev").addEventListener("click", () => changeMonth(-1));
document.querySelector(".next").addEventListener("click", () => changeMonth(1));
generateCalendar();
startDaySelect.addEventListener("change", generateCalendar);
backgroundSelect.addEventListener("change", generateCalendar);
});
</script>
</body>
</html>