-
Notifications
You must be signed in to change notification settings - Fork 0
/
Content_pglogin_agp.js
58 lines (54 loc) · 2.14 KB
/
Content_pglogin_agp.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
setTimeout(() => {
let link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.id = "theme-link";
// document.addEventListener('contextmenu', event => event.preventDefault());
/**
* Changes the CSS file to the one that matches the theme.
* @param theme - The name of the theme to apply.
*/
function patchCSS(theme) {
if(theme === "light"){
// Light Theme
console.log("light")
localStorage.setItem("plus-theme", "light")
link.href = browser.runtime.getURL("css/agp/light.css")
}else if(theme === "dark"){
// Dark Theme
console.log("dark")
localStorage.setItem("plus-theme", "dark")
link.href = browser.runtime.getURL("css/agp/dark.css")
}
}
// Retrieves the theme from localStorage
if(localStorage.getItem("plus-theme") === null & localStorage.getItem("plus-theme") !== "dark" && localStorage.getItem("plus-theme") !== "light"){
// No theme has been set, we set the default one
console.log("Pas de thème trouvé ! Le thème clair est appliqué.")
patchCSS("light")
}else if(localStorage.getItem("plus-theme") === "light"){
// Light Theme
patchCSS("light")
}else if(localStorage.getItem("plus-theme") === "dark"){
// Dark Theme
patchCSS("dark")
}
document.getElementsByTagName("head")[0].appendChild(link);
// Theme switcher
let themeSwitcher = document.createElement("a");
themeSwitcher.id = "theme-switcher";
themeSwitcher.href = "#";
themeSwitcher.title = "Changer de thème";
themeSwitcher.innerHTML = "Changer de thème (CAS AGP)";
themeSwitcher.addEventListener("click", function(e){
e.preventDefault();
if(localStorage.getItem("plus-theme") === "light"){
patchCSS("dark")
}else if(localStorage.getItem("plus-theme") === "dark"){
patchCSS("light")
}else{
patchCSS("light")
}
});
document.body.appendChild(themeSwitcher);
}, 50);