-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
66 lines (54 loc) · 2.27 KB
/
scripts.js
File metadata and controls
66 lines (54 loc) · 2.27 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
// This function hides the loading screen once the page is fully loaded.
window.addEventListener('load', function () {
document.querySelector('.loading-screen').style.display = 'none';
// Initialize the background color based on the switch state when the page loads
const checkBox = document.querySelector('.cb');
if (checkBox) {
updateBackgroundColor(checkBox.checked);
// Add event listener for changes on the switch to update the background color
checkBox.addEventListener('change', function () {
updateBackgroundColor(this.checked);
});
}
});
// This function sets the 'active' class on the current navigation link.
function setActiveLink() {
const currentPath = window.location.pathname.split('/').pop();
const navLinks = document.querySelectorAll('.header__nav a');
navLinks.forEach(link => {
if (link.getAttribute('href') === currentPath) {
link.classList.add('active');
}
});
}
// This function updates the background color and header title color based on the switch's state.
function updateBackgroundColor(isChecked) {
const body = document.body;
const headerTitle = document.querySelector('.header__title');
if (isChecked) {
body.style.backgroundColor = 'rgb(37, 31, 41)';
document.cookie = "userTheme=dark; path=/"; // Store the theme preference in a cookie
if (headerTitle) {
headerTitle.style.color = 'white';
}
} else {
body.style.backgroundColor = '#F0F8FF';
document.cookie = "userTheme=light; path=/"; // Store the theme preference in a cookie
if (headerTitle) {
headerTitle.style.color = 'black';
}
}
}
// Ensure the setActiveLink function is called when the DOM is fully loaded
window.addEventListener('DOMContentLoaded', setActiveLink);
// Get URL parameters and check for specific view settings
document.addEventListener("DOMContentLoaded", function() {
function getQueryParam(param) {
var location = window.location.href;
var params = new URLSearchParams(location.substring(location.indexOf('?')));
return params.get(param);
}
if (getQueryParam('view') === 'signup') {
document.getElementById('reg-log').checked = true;
}
});