-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
268 lines (218 loc) · 9.7 KB
/
script.js
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
let taskCounter = 0;
document.getElementById('addTaskButton').addEventListener('click', function() {
taskCounter++;
const tasksContainer = document.getElementById('tasksContainer');
const taskDiv = document.createElement('div');
taskDiv.className = 'task';
taskDiv.innerHTML = `
<label for="taskName${taskCounter}">Task Name:</label>
<input type="text" id="taskName${taskCounter}" required>
<label for="taskDetails${taskCounter}">Task Details:</label>
<input type="text" id="taskDetails${taskCounter}" required>
`;
tasksContainer.appendChild(taskDiv);
});
document.getElementById('homeworkForm').addEventListener('submit', function(e) {
e.preventDefault();
const dateGiven = new Date(document.getElementById('dateGiven').value);
let dueDate = new Date(document.getElementById('dueDate').value);
dueDate.setDate(dueDate.getDate());
const tasks = [];
for (let i = 1; i <= taskCounter; i++) {
const taskName = document.getElementById(`taskName${i}`).value;
const taskDetails = document.getElementById(`taskDetails${i}`).value;
tasks.push({ name: taskName, details: taskDetails.split('+') });
}
const timeDiff = dueDate - dateGiven;
const daysAvailable = Math.ceil(timeDiff / (1000 * 60 * 60 * 24));
const tasksPerDay = Math.ceil(tasks.length / daysAvailable);
// Update the assignments object for the calendar
for (let i = 0; i < daysAvailable; i++) {
const currentDay = new Date(dateGiven);
currentDay.setDate(currentDay.getDate() + i);
const dateString = `${currentDay.getFullYear()}-${currentDay.getMonth() + 1}-${currentDay.getDate()}`;
if (!assignments[dateString]) {
assignments[dateString] = [];
}
const startIndex = i * tasksPerDay;
const endIndex = startIndex + tasksPerDay;
const tasksForTheDay = tasks.slice(startIndex, endIndex);
tasksForTheDay.forEach(task => {
assignments[dateString].push(`${task.name}: ${task.details.join(', ')}`);
});
}
// Update the calendar to reflect the new assignments
updateCalendar();
});
document.addEventListener('DOMContentLoaded', function() {
const subtitle = document.getElementById('subtitle');
let subtitleText = [
"You are Mark. You are Mark. You are Mark. You are Mark. You are Mark. You are Mark. You are Mark.",
"Fuck off calendars!",
"Calendars aren't eating a penny from me!",
"Hello, You are Mark. No worries this is normal amnesia.",
"You need to do your homework, you know that right? RIGHT?!",
"Shut the fuck up and go studying!",
"Bruh when is the summer gonna start?",
"Programming stuff starts in the next quarter there is not much time left; I hope.",
"You are a fucking idiot, you know that right? RIGHT?!",
];
subtitle.textContent = subtitleText[Math.floor(Math.random() * subtitleText.length)];
});
const backgrounds = [];
document.addEventListener('DOMContentLoaded', async function() {
const sideMenu = document.getElementById('sideMenu');
try {
const response = await fetch('backgrounds/');
const html = await response.text();
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const links = doc.querySelectorAll('a');
links.forEach(link => {
const href = link.getAttribute('href');
if (href.match(/\.(jpg|jpeg|png|gif)$/i)) {
backgrounds.push(`${href}`);
}
});
backgrounds.forEach((bg, index) => {
const backgroundOption = document.createElement('div');
backgroundOption.className = 'background-option';
backgroundOption.style.backgroundImage = `url('${bg}')`;
backgroundOption.onclick = () => changeBackground(bg);
sideMenu.appendChild(backgroundOption);
});
// Pick a random background by default
if (backgrounds.length > 0) {
const randomBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)];
changeBackground(randomBackground);
}
} catch (error) {
console.error('Error fetching backgrounds:', error);
}
});
let isthemeSelectorOpen = false;
function togglethemeSelector() {
const themeSelector = document.getElementById('themeSelector');
themeSelector.classList.toggle('open');
}
document.getElementById('themeButton').addEventListener('click', togglethemeSelector);
function changeBackground(backgroundUrl) {
document.body.style.backgroundImage = `url('${backgroundUrl}')`;
}
function addAssignment(dateString, assignment) {
if (!assignments[dateString]) {
assignments[dateString] = [];
}
assignments[dateString].push(assignment);
updateCalendar();
}
function removeAssignment(dateString, index) {
if (assignments[dateString] && assignments[dateString].length > index) {
assignments[dateString].splice(index, 1);
if (assignments[dateString].length === 0) {
delete assignments[dateString];
}
updateCalendar();
}
}
const calendar = document.getElementById('calendar');
const monthYear = document.getElementById('monthYear');
const calendarDays = document.getElementById('calendarDays');
const prevMonthBtn = document.getElementById('prevMonth');
const nextMonthBtn = document.getElementById('nextMonth');
let currentDate = new Date();
let assignments = {};
function generateCalendar(year, month) {
const firstDay = new Date(year, month, 1);
const lastDay = new Date(year, month + 1, 0);
const daysInMonth = lastDay.getDate();
const startingDay = firstDay.getDay();
monthYear.textContent = `${firstDay.toLocaleString('default', { month: 'long' })} ${year}`;
calendarDays.innerHTML = '';
for (let i = 0; i < startingDay; i++) {
calendarDays.innerHTML += '<div class="day-cube"></div>';
}
for (let day = 1; day <= daysInMonth; day++) {
const dayCube = document.createElement('div');
dayCube.classList.add('day-cube');
const dayNumber = document.createElement('div');
dayNumber.classList.add('day-number');
dayNumber.textContent = day;
const dayAssignments = document.createElement('div');
dayAssignments.classList.add('day-assignments');
dayCube.appendChild(dayNumber);
dayCube.appendChild(dayAssignments);
if (year === currentDate.getFullYear() && month === currentDate.getMonth() && day === currentDate.getDate()) {
dayCube.classList.add('today');
}
const dateString = `${year}-${month + 1}-${day}`;
if (assignments[dateString] && assignments[dateString].length > 0) {
dayCube.classList.add('has-assignment');
}
dayCube.addEventListener('click', () => showAssignments(year, month, day));
calendarDays.appendChild(dayCube);
}
} function showAssignments(year, month, day) {
const dateString = `${year}-${month + 1}-${day}`;
const popup = document.getElementById('assignmentPopup');
const popupDate = document.getElementById('popupDate');
const assignmentList = document.getElementById('assignmentList');
popupDate.textContent = new Date(year, month, day).toDateString();
assignmentList.innerHTML = '';
if (assignments[dateString]) {
assignments[dateString].forEach((assignment, index) => {
const li = document.createElement('li');
li.textContent = assignment;
const removeButton = document.createElement('button');
removeButton.textContent = 'Remove';
removeButton.classList.add('remove-assignment');
removeButton.addEventListener('click', () => removeAssignment(dateString, index));
li.appendChild(removeButton);
assignmentList.appendChild(li);
});
} else {
assignmentList.innerHTML = '<li>No assignments for this day</li>';
}
popup.style.display = 'block';
}
function removeAssignment(dateString, index) {
assignments[dateString].splice(index, 1);
if (assignments[dateString].length === 0) {
delete assignments[dateString];
}
showAssignments(...dateString.split('-').map(Number));
updateCalendar();
}
document.getElementById('closePopup').addEventListener('click', () => {
document.getElementById('assignmentPopup').style.display = 'none';
});
// Add this to your existing code to close the popup when clicking outside
window.addEventListener('click', (event) => {
const popup = document.getElementById('assignmentPopup');
if (event.target === popup) {
popup.style.display = 'none';
}
});
function addAssignment(year, month, day) {
const assignment = prompt('Enter assignment for this day:');
if (assignment) {
const dateString = `${year}-${month + 1}-${day}`;
if (!assignments[dateString]) {
assignments[dateString] = [];
}
assignments[dateString].push(assignment);
updateCalendar();
}
}
function updateCalendar() {
generateCalendar(currentDate.getFullYear(), currentDate.getMonth());
}
prevMonthBtn.addEventListener('click', () => {
currentDate.setMonth(currentDate.getMonth() - 1);
updateCalendar();
});
nextMonthBtn.addEventListener('click', () => {
currentDate.setMonth(currentDate.getMonth() + 1);
updateCalendar();
});
updateCalendar();