-
Notifications
You must be signed in to change notification settings - Fork 3
/
darkmode.js
52 lines (40 loc) · 1.36 KB
/
darkmode.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
(function() {
let onpageLoad = localStorage.getItem("theme") || "";
let element = document.body;
element.classList.add(onpageLoad);
document.getElementById("theme").textContent =
localStorage.getItem("theme") || "light";
})();
function darkmode_toggle() {
let element = document.body;
element.classList.toggle("dark-mode");
let theme = localStorage.getItem("theme");
if (theme && theme === "dark-mode") {
localStorage.setItem("theme", "");
} else {
localStorage.setItem("theme", "dark-mode");
}
}
function comment_control(){
let theme = localStorage.getItem("theme");
var cisrc=document.getElementsByClassName('giscus-frame')[0].src;
console.log(cisrc);
console.log(theme);
if (theme && theme === "dark-mode") {
cisrc = cisrc.replace("preferred_color_scheme", "dark");
} else {
cisrc = cisrc.replace("dark", "preferred_color_scheme");
}
console.log(cisrc);
document.getElementsByClassName('giscus-frame')[0].src = cisrc;
/*if (cisrc.includes("preferred_color_scheme")) {
cisrc = cisrc.replace("preferred_color_scheme", "dark");
} else if (cisrc.includes("dark")) {
cisrc = cisrc.replace("dark", "preferred_color_scheme");
}
console.log(cisrc);
document.getElementsByClassName('giscus-frame')[0].src = cisrc;
*/
document.getElementsByClassName('giscus-frame')[0].contentWindow.location.reload();
var stop=true;
}