-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
379 lines (317 loc) · 11.9 KB
/
script.js
File metadata and controls
379 lines (317 loc) · 11.9 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
//search bar:
function search(engine) {
const query = document.getElementById('search-input').value.trim();
if (!query) return;
const urls = {
google: `https://www.google.com/search?q=${query}`,
duckduckgo: `https://duckduckgo.com/?q=${query}`,
bing: `https://www.bing.com/search?q=${query}`,
youtube: `https://www.youtube.com/results?search_query=${query}`
};
window.open(urls[engine], '_blank');
}
// Welcomer:
document.addEventListener('DOMContentLoaded', function() {
try {
const hour = new Date().getHours();
let greeting;
if (hour < 12) greeting = "Morning!";
else if (hour < 18) greeting = "Good afternoon!";
else greeting = "Evening!";
const greetingElement = document.getElementById('welcomer');
if (greetingElement) {
greetingElement.textContent = `${greeting}`;
} else {
console.error("Failed to welcome user: Element with ID 'welcomer' was not found!");
}
} catch (error) {
console.error("Error in welcoming script:", error);
}
});
// Clock:
document.addEventListener('DOMContentLoaded', () => {
const clock = document.getElementById('clock');
if (!clock) {
console.error("somehow, the clock was not found!");
return;
}
function update() {
clock.textContent = new Date().toLocaleTimeString();
}
update();
setInterval(update, 1000);
});
// date:
document.getElementById('date').textContent = new Date().toLocaleDateString('en-US', {
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric'
});
// fuckass code - weather code is broken fix it later.
// document.addEventListener('DOMContentLoaded', async () => {
// const weatherResult = document.getElementById('weather-result');
// try {
// //Approximate location using IP (if u r reading dis, i dont collect ur ip nor i want it.)
// const ipLoc = await fetch('https://ipapi.co/json/').then(res => res.json());
// //Fetch weather info
// const weather = await fetch(
// `https://api.open-meteo.com/v1/forecast?latitude=${ipLoc.latitude}&longitude=${ipLoc.longitude}¤t_weather=true&temperature_unit=celsius`
// ).then(res => res.json());
// //Display info
// weatherResult.innerHTML = `
// <h3>${weather.current_weather.temperature}°C • ${getWeatherIcon(weather.current_weather.weathercode)}</h3>
// <h3>${ipLoc.city || 'Your location'}</h3>
// `;
// } catch (error) {
// weatherResult.innerHTML = `
// <p>Weather unavailable :(</p>
// <button onclick="retryWeather()">Retry</button>
// `; if you are reading this. yes, AI helped me script this website, does that make me a bad person? I'm not sure.
// console.error("Weather error happend!:", error);
// }
// });
// function retryWeather() {
// document.getElementById('weather-result').textContent = "Loading...";
// document.dispatchEvent(new Event('DOMContentLoaded'));
// }
// function getWeatherIcon(code) {
// const icons = {
// 0: "☀️", 1: "🌤️", 2: "⛅", 3: "☁️",
// 45: "🌫️", 51: "🌧️", 61: "🌧️", 80: "🌦️"
// };
// return icons[code] || "🌈";
// }
// settings:
// Get modal
var modal = document.getElementById("myModal");
var btn = document.getElementById("myBtn");
//<span> element closes the modal
var span = document.getElementsByClassName("close")[0];
// When user clicks button open modal
btn.onclick = function() {
modal.style.display = "block";
}
// When user clicks <span>, close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When clicks outside close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
//settings toggles
//clock
function handleClockToggle() {
const clockElement = document.getElementById('clockLine');
if (clockElement) {
const isClockHidden = clockElement.style.display === 'none';
clockElement.style.display = isClockHidden ? 'inline' : 'none';
// Save the preference to localStorage
localStorage.setItem('clockVisibility', isClockHidden ? 'visible' : 'hidden');
} else {
console.error("Clock element not found!");
}
}
function loadClockPreference() {
const clockElement = document.getElementById('clockLine');
if (clockElement) {
const clockVisibility = localStorage.getItem('clockVisibility');
if (clockVisibility) {
clockElement.style.display = clockVisibility === 'visible' ? 'inline' : 'none';
}
}
}
window.addEventListener('DOMContentLoaded', loadClockPreference);
//date
function handleDateToggle() {
const dateElement = document.getElementById('dateLine');
if (dateElement) {
// Toggle the display
const isDateHidden = dateElement.style.display === 'none';
dateElement.style.display = isDateHidden ? 'block' : 'none';
// Save the preference to localStorage
localStorage.setItem('dateVisibility', isDateHidden ? 'visible' : 'hidden');
} else {
console.error("Date element not found!");
}
}
function loadDatePreference() {
const dateElement = document.getElementById('dateLine');
if (dateElement) {
const dateVisibility = localStorage.getItem('dateVisibility');
// If there's a saved preference, apply it
if (dateVisibility) {
dateElement.style.display = dateVisibility === 'visible' ? 'block' : 'none';
}
}
}
window.addEventListener('DOMContentLoaded', loadDatePreference);
//QuickLinks
function handleQLToggle() {
const dateElement = document.getElementById('quicklinksDiv');
if (dateElement) {
const isQLHidden = dateElement.style.display === 'none';
dateElement.style.display = isQLHidden ? 'initial' : 'none';
localStorage.setItem('qlVisibility', isQLHidden ? 'visible' : 'hidden');
} else {
console.error("QL element not found!");
}
}
function loadQLPreference() {
const qlElement = document.getElementById('quicklinksDiv');
if (qlElement) {
const qlVisibility = localStorage.getItem('qlVisibility');
if (qlVisibility) {
qlElement.style.display = qlVisibility === 'visible' ? 'initial' : 'none';
}
}
}
window.addEventListener('DOMContentLoaded', loadQLPreference);
//Background Handler:
// Presets
const presets = [
'assets/backgrounds/1.gif',
'assets/backgrounds/2.gif',
'assets/backgrounds/3.gif',
'assets/backgrounds/4.gif',
'assets/backgrounds/5.gif',
'assets/backgrounds/6.gif',
'assets/backgrounds/7.gif',
'assets/backgrounds/8.gif',
'assets/backgrounds/9.gif',
'assets/backgrounds/10.gif',
];
// DOM elements
const presetBtns = document.getElementById('preset-btns');
const bgUrlInput = document.getElementById('bg-url');
const setUrlBtn = document.getElementById('set-url-btn');
const bgUpload = document.getElementById('bg-upload');
const setUploadBtn = document.getElementById('set-upload-btn');
const resetBtn = document.getElementById('reset-btn');
const randomLoadCheck = document.getElementById('random-load');
const enableCycleCheck = document.getElementById('enable-cycle');
const cycleTimeSelect = document.getElementById('cycle-time');
const nextBgBtn = document.getElementById('next-bg-btn');
// State variables
let currentPresetIndex = 0;
let cycleInterval = null;
let isCycling = false;
// Initialize UI from localStorage
function initFromStorage() {
// Load saved background
const savedBg = localStorage.getItem('savedBackground');
if (savedBg) {
setBackground(savedBg, false);
}
// Load cycling preferences
if (localStorage.getItem('randomLoad') === 'true') {
randomLoadCheck.checked = true;
showRandomBackground();
}
if (localStorage.getItem('enableCycle') === 'true') {
enableCycleCheck.checked = true;
const minutes = parseInt(localStorage.getItem('cycleTime') || '5');
cycleTimeSelect.value = minutes;
startCycling(minutes);
}
}
// Create preset buttons
function createPresetButtons() {
presetBtns.innerHTML = '';
presets.forEach((url, index) => {
const btn = document.createElement('div');
btn.className = 'preset-btn';
btn.style.backgroundImage = `url(${url})`;
btn.title = `Preset ${index + 1}`;
btn.onclick = () => {
setBackground(url, true);
currentPresetIndex = index;
stopCycling();
};
presetBtns.appendChild(btn);
});
}
// Set background function
function setBackground(imageSrc, save = true) {
document.body.style.backgroundImage = `url(${imageSrc})`;
if (save) {
localStorage.setItem('savedBackground', imageSrc);
}
}
// Show next preset background
function showNextBackground() {
currentPresetIndex = (currentPresetIndex + 1) % presets.length;
setBackground(presets[currentPresetIndex], true);
}
// Show random background
function showRandomBackground() {
const randomIndex = Math.floor(Math.random() * presets.length);
currentPresetIndex = randomIndex;
setBackground(presets[randomIndex], true);
}
// Start background cycling
function startCycling(minutes) {
stopCycling();
isCycling = true;
const milliseconds = minutes * 60 * 1000;
cycleInterval = setInterval(showNextBackground, milliseconds);
localStorage.setItem('enableCycle', 'true');
localStorage.setItem('cycleTime', minutes.toString());
}
// Stop background cycling
function stopCycling() {
if (cycleInterval) {
clearInterval(cycleInterval);
cycleInterval = null;
}
isCycling = false;
localStorage.setItem('enableCycle', 'false');
}
// Event listeners
setUrlBtn.addEventListener('click', () => {
const url = bgUrlInput.value.trim();
if (url) {
setBackground(url, true);
stopCycling();
}
});
setUploadBtn.addEventListener('click', () => {
const file = bgUpload.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
setBackground(e.target.result, true);
stopCycling();
};
reader.readAsDataURL(file);
}
});
resetBtn.addEventListener('click', () => {
localStorage.removeItem('savedBackground');
document.body.style.backgroundImage = '';
stopCycling();
});
randomLoadCheck.addEventListener('change', (e) => {
localStorage.setItem('randomLoad', e.target.checked.toString());
});
enableCycleCheck.addEventListener('change', (e) => {
if (e.target.checked) {
const minutes = parseInt(cycleTimeSelect.value);
startCycling(minutes);
} else {
stopCycling();
}
});
cycleTimeSelect.addEventListener('change', (e) => {
if (isCycling) {
const minutes = parseInt(e.target.value);
startCycling(minutes);
}
});
nextBgBtn.addEventListener('click', showNextBackground);
// Initialize the app
createPresetButtons();
initFromStorage();