This repository was archived by the owner on Nov 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscripts.js
More file actions
504 lines (373 loc) · 15.4 KB
/
Copy pathscripts.js
File metadata and controls
504 lines (373 loc) · 15.4 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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
function updateTime() {
const timeElement = document.getElementById('timeElement');
const currentDate = new Date();
// Extract hours and minutes
let hours = currentDate.getHours();
const minutes = currentDate.getMinutes();
// Convert to 12-hour format
const isPM = hours >= 12;
hours = hours % 12;
hours = hours ? hours : 12; // Handle midnight (0 becomes 12)
// Format minutes to always show two digits
const formattedMinutes = minutes < 10 ? '0' + minutes : minutes;
// Combine hours and minutes without AM/PM
const formattedTime = `${hours}:${formattedMinutes}`;
// Update the time element
timeElement.textContent = formattedTime;
}
// Call the updateTime function every second to keep the time updated
setInterval(updateTime, 1000);
// Initial call to display the time immediately when the page loads
updateTime();
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const today = new Date();
const dayOfWeek = days[today.getDay()];
const dateOfMonth = today.getDate();
// Format the output as "Sun 21"
const formattedDate = `${dayOfWeek} ${dateOfMonth}`;
// Update the HTML element with id="currentDay"
document.getElementById('currentDay').textContent = formattedDate;
const apiKey = 'db5a5dd4233284f22f468c35dad5f8ff';
async function getWeather(cityName) {
const url = `https://api.openweathermap.org/data/2.5/weather?q=${cityName}&appid=${apiKey}&units=metric`;
const response = await fetch(url);
const data = await response.json();
if (data.cod === 200) {
const cityName = data.name;
const temperature = Math.round(data.main.temp);
const description = data.weather[0].description;
const icon = data.weather[0].icon;
updateWeatherInfo(cityName, temperature, description, icon);
localStorage.setItem('savedCity', cityName); // Save city name to local storage
} else {
console.log('City not found. Please check the city name and try again.');
}
}
function updateWeatherInfo(cityName, temperature, description, icon) {
document.getElementById('city-name').textContent = cityName;
document.getElementById('temperature').textContent = `${temperature}°`;
document.getElementById('description').textContent = description;
const iconUrl = `https://openweathermap.org/img/wn/${icon}@2x.png`;
document.getElementById('weather-icon').src = iconUrl;
}
function handleCitySearch() {
const cityName = document.getElementById('city-input').value;
if (cityName) {
getWeather(cityName);
}
}
// Load saved city weather on page load
document.addEventListener('DOMContentLoaded', () => {
const savedCity = localStorage.getItem('savedCity');
if (savedCity) {
getWeather(savedCity);
}
});
function showPopup() {
document.getElementById('overlay').style.display = 'block';
var popup = document.getElementById('popup');
popup.style.display = 'flex';
}
function updateName() {
var newName = document.getElementById('newName').value;
document.getElementById('name').textContent = newName;
// Save the new name to localStorage
localStorage.setItem('savedName', newName);
closePopup();
}
function closePopup() {
document.getElementById('overlay').style.display = 'none';
var popup = document.getElementById('popup');
popup.style.display = 'none';
}
// Function to load the saved name when the page loads
window.onload = function() {
var savedName = localStorage.getItem('savedName');
if (savedName) {
document.getElementById('name').textContent = savedName;
}
};
const checkbox = document.getElementById('backgroundToggle');
function setBackground() {
const imageUrl = 'https://picsum.photos/1920/1080/?random&blur';
document.documentElement.style.backgroundImage = `url(${imageUrl})`;
document.documentElement.style.backgroundSize = 'cover';
}
function handleCheckboxChange() {
if (checkbox.checked) {
localStorage.setItem('backgroundToggle', 'checked');
setBackground();
} else {
localStorage.removeItem('backgroundToggle');
document.body.style.backgroundImage = '';
document.body.style.backgroundColor = '#121212';
}
}
// Check the localStorage to set the checkbox state on page load
if (localStorage.getItem('backgroundToggle') === 'checked') {
checkbox.checked = true;
setBackground();
}
// Add event listener to the checkbox
checkbox.addEventListener('change', handleCheckboxChange);
// Set an interval to change the background every 60 minutes (3600000 milliseconds)
setInterval(() => {
if (checkbox.checked) {
setBackground();
}
}, 3600000);
// Function to set the color to both the CSS variable and local storage
function setColorAndStore(color) {
document.documentElement.style.setProperty('--accent', color);
localStorage.setItem('selectedColor', color);
}
// Event listener for clicking the button to show the color picker
// Event listener for when the color picker value changes
document.getElementById('colorPicker').addEventListener('input', function() {
let selectedColor = this.value;
// Set the color and store it in local storage
setColorAndStore(selectedColor);
});
// Check local storage on page load to set the color if it was previously selected
document.addEventListener('DOMContentLoaded', function() {
let storedColor = localStorage.getItem('selectedColor');
if (storedColor) {
setColorAndStore(storedColor);
}
});
// Function to set the color to both the CSS variable and local storage
function setColorAndStor(color) {
document.documentElement.style.setProperty('--srcbar', color);
localStorage.setItem('selectedColo', color);
}
// Event listener for clicking the button to show the color picker
// Event listener for when the color picker value changes
document.getElementById('colorPicker').addEventListener('input', function() {
let hexColor = this.value;
let rgbaColor = hexToRgba(hexColor, 0.429); // Always set alpha to 0.329 (33% opacity)
// Set the color and store it in local storage
setColorAndStor(rgbaColor);
});
// Function to convert hex to RGBA with fixed alpha
function hexToRgba(hex, alpha) {
// Remove the hash at the start if it's there
hex = hex.replace(/^#/, '');
// Parse r, g, b values
let bigint = parseInt(hex, 16);
let r = (bigint >> 16) & 255;
let g = (bigint >> 8) & 255;
let b = bigint & 255;
// Return RGBA string with fixed alpha
return `rgba(${r},${g},${b},${alpha})`;
}
// Check local storage on page load to set the color if it was previously selected
document.addEventListener('DOMContentLoaded', function() {
let storedColo = localStorage.getItem('selectedColo');
if (storedColo) {
setColorAndStor(storedColo);
}
});
document.addEventListener('DOMContentLoaded', function () {
var checkbox = document.getElementById('toggle');
var container = document.querySelector('.bg');
// Check localStorage for saved state
var isChecked = localStorage.getItem('newsDisabled') === 'true';
checkbox.checked = isChecked;
updateContainerVisibility(isChecked);
// Function to update container visibility based on checkbox state
function updateContainerVisibility(disabled) {
if (disabled) {
container.style.display = "none";
} else {
container.style.display = "block";
}
}
// Event listener for checkbox change
checkbox.addEventListener('change', function() {
var isChecked = checkbox.checked;
localStorage.setItem('newsDisabled', isChecked); // Save state to localStorage
updateContainerVisibility(isChecked);
});
});
window.addEventListener('scroll', function() {
var searchContainer = document.getElementById('searchContainer');
if (window.pageYOffset > 310) { // Adjust the value if needed
searchContainer.classList.add('sticky');
} else {
searchContainer.classList.remove('sticky');
}
});
let deleteMode = false;
function toggleDeleteMode() {
deleteMode = !deleteMode;
const linkContainers = document.querySelectorAll('.link-container');
linkContainers.forEach(container => {
const deleteButton = container.querySelector('.delete-button');
deleteButton.style.display = deleteMode ? 'block' : 'none';
container.classList.toggle('delete-mode', deleteMode);
});
}
function addLink() {
const url = document.getElementById('urlInput').value;
const faviconUrl = `https://www.google.com/s2/favicons?domain=${url}`;
const link = document.createElement('a');
link.href = url;
link.target = '_blank';
link.innerHTML = `<img src="${faviconUrl}" alt="icon">`;
const deleteButton = document.createElement('button');
deleteButton.innerHTML = 'X';
deleteButton.className = 'delete-button';
deleteButton.style.display = deleteMode ? 'block' : 'none';
deleteButton.onclick = function() {
deleteLink(url);
};
const linkContainer = document.createElement('div');
linkContainer.className = 'link-container';
linkContainer.appendChild(link);
linkContainer.appendChild(deleteButton);
document.getElementById('iconsContainer').appendChild(linkContainer);
const links = JSON.parse(localStorage.getItem('links')) || [];
links.push({ url: url });
localStorage.setItem('links', JSON.stringify(links));
document.getElementById('urlInput').value = '';
}
function loadLinks() {
const links = JSON.parse(localStorage.getItem('links')) || [];
const iconsContainer = document.getElementById('iconsContainer');
links.forEach(linkData => {
const faviconUrl = `https://www.google.com/s2/favicons?domain=${linkData.url}`;
const link = document.createElement('a');
link.href = linkData.url;
link.target = '_blank';
link.innerHTML = `<img src="${faviconUrl}" alt="icon">`;
const deleteButton = document.createElement('button');
deleteButton.innerHTML = 'X';
deleteButton.className = 'delete-button';
deleteButton.style.display = deleteMode ? 'block' : 'none';
deleteButton.onclick = function() {
deleteLink(linkData.url);
};
const linkContainer = document.createElement('div');
linkContainer.className = 'link-container';
linkContainer.appendChild(link);
linkContainer.appendChild(deleteButton);
iconsContainer.appendChild(linkContainer);
});
}
function deleteLink(url) {
const iconsContainer = document.getElementById('iconsContainer');
const linkContainers = iconsContainer.getElementsByClassName('link-container');
for (let i = 0; i < linkContainers.length; i++) {
const link = linkContainers[i].getElementsByTagName('a')[0];
if (link && link.href === url) {
iconsContainer.removeChild(linkContainers[i]);
break;
}
}
let links = JSON.parse(localStorage.getItem('links')) || [];
links = links.filter(linkData => linkData.url !== url);
localStorage.setItem('links', JSON.stringify(links));
}
window.onload = loadLinks;
const searchEngineSelector = document.getElementById('searchEngine');
const searchForm = document.getElementById('searchForm');
const searchInput = document.getElementById('searchInput');
// Load the previously selected search engine from local storage
const savedEngine = localStorage.getItem('selectedSearchEngine');
if (savedEngine) {
searchEngineSelector.value = savedEngine;
searchForm.action = savedEngine;
const selectedOptionText = searchEngineSelector.options[searchEngineSelector.selectedIndex].text.trim();
searchInput.placeholder = `Search on ${selectedOptionText}...`;
}
searchEngineSelector.addEventListener('change', function() {
const selectedEngine = this.value;
searchForm.action = selectedEngine;
const selectedOptionText = this.options[this.selectedIndex].text.trim();
searchInput.placeholder = `Search on ${selectedOptionText}...`;
// Save the selected search engine to local storage
localStorage.setItem('selectedSearchEngine', selectedEngine);
});
// Ensure form submission works on Enter key press
searchInput.addEventListener('keypress', function(event) {
if (event.key === 'Enter') {
event.preventDefault();
searchForm.submit();
}
});
document.getElementById('searchInput').addEventListener('input', function() {
let query = this.value;
if (query.length > 0) {
fetchSuggestions(query);
} else {
clearSuggestions();
}
});
function fetchSuggestions(query) {
const url = `https://suggestqueries.google.com/complete/search?client=chrome&q=${encodeURIComponent(query)}&callback=handleSuggestions`;
const script = document.createElement('script');
script.src = url;
document.body.appendChild(script);
document.body.removeChild(script);
}
function handleSuggestions(data) {
displaySuggestions(data[1]);
}
function displaySuggestions(suggestions) {
const suggestionsList = document.getElementById('suggestions');
clearSuggestions();
suggestions.forEach(suggestion => {
const suggestionItem = document.createElement('p');
suggestionItem.textContent = suggestion;
suggestionItem.classList.add('suggestion-item');
suggestionItem.addEventListener('click', function() {
document.getElementById('searchInput').value = suggestion;
clearSuggestions();
document.getElementById('searchForm').submit(); // Submit the form
});
suggestionsList.appendChild(suggestionItem);
});
}
function clearSuggestions() {
const suggestionsList = document.getElementById('suggestions');
suggestionsList.innerHTML = '';
}
document.getElementById('searchEngine').addEventListener('change', function() {
document.getElementById('searchForm').action = this.value;
});
const avatar = document.querySelector('.avatar');
const fileInput = document.getElementById('file-input');
// Load image from local storage if it exists
const storedImage = localStorage.getItem('uploadedAvatar');
if (storedImage) {
avatar.src = storedImage;
}
avatar.addEventListener('click', () => {
fileInput.click();
});
fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
const result = e.target.result;
avatar.src = result;
localStorage.setItem('uploadedAvatar', result); // Save the image to local storage
};
reader.readAsDataURL(file);
}
});
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
document.getElementById("defaultOpen").click();