-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
executable file
·44 lines (43 loc) · 1.34 KB
/
content.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
let cssId = "darkThemeStyleSheet";
try {
let head = document.getElementsByTagName("head")[0];
let link = document.createElement("link");
link.id = cssId;
link.rel = "stylesheet";
link.type = "text/css";
link.href = chrome.runtime.getURL("css/dark_theme.css");
link.media = "all";
head.appendChild(link);
console.log("Dark mode enabled!");
} catch (err) {
console.log("Error ", err);
}
chrome.storage.sync.get(["GDDM-active"], function (result) {
if (result["GDDM-active"] === "false") {
if (document.getElementById(cssId)) {
let linkToCSS = document.getElementById(cssId);
linkToCSS.parentElement.removeChild(linkToCSS);
}
}
});
chrome.runtime.onMessage.addListener(function (message) {
if (message === "true") {
// If link is not there, add it
if (!document.getElementById(cssId)) {
let head = document.getElementsByTagName("head")[0];
let link = document.createElement("link");
link.id = cssId;
link.rel = "stylesheet";
link.type = "text/css";
link.href = chrome.runtime.getURL("css/dark_theme.css");
link.media = "all";
head.appendChild(link);
}
} else {
// If the link is there, remove it
if (document.getElementById(cssId)) {
let linkToCSS = document.getElementById(cssId);
linkToCSS.parentElement.removeChild(linkToCSS);
}
}
});