-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
72 lines (61 loc) · 2.34 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
////////////////////////////////////////// for debugging
// const body = document.querySelector('body');
// const elements = document.querySelectorAll('div, .container, nav, footer'); // use * to add border to all elements
// let debug = false;
// body.addEventListener('click', function () {
// elements.forEach(element => {
// if (!debug) {
// element.style.border = '1px solid var(--col-primary)';
// } else {
// element.style.border = '';
// }
// });
// debug = !debug;
// });
////////////////////////////////////////// dark-light background
const target = ['body', 'nav', 'footer', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'i', 'u', 'pre']
const changeTheme = document.querySelector('.change-theme');
function addDarkTheme(e) {
const target = document.querySelectorAll(e);
target.forEach(element => {
element.classList.add('dark-theme');
});
console.log('dark: ', changeTheme.querySelector('i'));
changeTheme.querySelector('i').classList.add('fa-sun');
changeTheme.querySelector('i').classList.remove('fa-moon');
}
function removeDarkTheme(e) {
const target = document.querySelectorAll(e);
target.forEach(element => {
element.classList.remove('dark-theme');
});
console.log('light: ', changeTheme.querySelector('i'));
changeTheme.querySelector('i').classList.remove('fa-sun');
changeTheme.querySelector('i').classList.add('fa-moon');
}
var dark = localStorage.getItem('dark-theme') === 'true';
if (dark) {
addDarkTheme(target);
}
changeTheme.addEventListener('click', function () {
dark = !dark;
if (dark) {
addDarkTheme(target);
} else {
removeDarkTheme(target);
}
localStorage.setItem('dark-theme', dark);
});
////////////////////////////////////////// EN/DE Languages
////////////////////////////////////////// update footer year
const currentYear = new Date().getFullYear();
const currentYearElement = document.querySelector('.currentYear')
if (currentYearElement) {
currentYearElement.textContent = currentYear;
}
////////////////////////////////////////// add margin-right to eeach element in education & skills section
const educationSkills = document.querySelectorAll('.education-skills ul li i')
console.log(educationSkills);
educationSkills.forEach(e => {
e.classList.add('mr-3');
});