-
Notifications
You must be signed in to change notification settings - Fork 2
/
popup.js
27 lines (25 loc) · 881 Bytes
/
popup.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
/**
* Change the theme of the current page.
*
*/
let ts = document.getElementById('theme-switch');
ts.onchange = function(element) {
chrome.tabs.query({active: true, currentWindow: true}, function(e) {
if(ts.checked){
chrome.tabs.executeScript(
{code: 'document.querySelector("body").classList.add("dark");document.querySelector("body").classList.remove("light");'
});
localStorage.setItem("tg-theme", "dark");
}
else{
chrome.tabs.executeScript(
{code: 'document.querySelector("body").classList.add("light");document.querySelector("body").classList.remove("dark");'
});
localStorage.setItem("tg-theme", "light");
}
});
};
window.onload = function(){
ts.checked = localStorage.getItem("tg-theme")!="light";
ts.onchange();
};