-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdark-mode.js
53 lines (47 loc) · 1.83 KB
/
dark-mode.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
document.addEventListener("DOMContentLoaded", function () {
const toggleSwitch = document.getElementById("dark-mode-toggle");
const currentTheme = localStorage.getItem("theme") ? localStorage.getItem("theme") : null;
const homeLogo = document.getElementById("home-logo");
const favicon = document.getElementById("favicon");
const githubLogo = document.getElementById("github-logo");
// Function to switch logos and favicons
function switchTheme(theme) {
if (theme === "dark-mode") {
document.body.classList.add("dark-mode");
if (homeLogo) homeLogo.src = "logos/home-logo-dark.png";
if (favicon) favicon.href = "logos/favicon-dark.ico";
if (githubLogo) githubLogo.src = "logos/github-logo-dark.png";
} else {
document.body.classList.remove("dark-mode");
if (homeLogo) homeLogo.src = "logos/home-logo-light.png";
if (favicon) favicon.href = "logos/favicon-light.ico";
if (githubLogo) githubLogo.src = "logos/github-logo-light.png";
}
}
if (currentTheme) {
switchTheme(currentTheme);
if (currentTheme === "dark-mode" && toggleSwitch) {
toggleSwitch.checked = true;
}
}
if (toggleSwitch) {
toggleSwitch.addEventListener("change", function () {
const theme = toggleSwitch.checked ? "dark-mode" : "light-mode";
switchTheme(theme);
localStorage.setItem("theme", theme);
});
}
});
function forcerModeClair() {
const body = document.body;
const wasDarkMode = body.classList.contains('dark-mode');
if (wasDarkMode) {
body.classList.remove('dark-mode');
}
return wasDarkMode;
}
function restaurerMode(wasDarkMode) {
if (wasDarkMode) {
document.body.classList.add('dark-mode');
}
}