-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnight-mode-web.js
40 lines (35 loc) · 1.49 KB
/
night-mode-web.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
const NIGHT_MODE_WEB_BUTTON_ELMT = document.getElementById("DAY-NIGHT-MODE");
const MODE_DAY_NIGHT_WEB_IMG = document.getElementById("mode-day-night");
const ARRAY_WEB_ELEMENTS = ['h1','h2','h3','h4','h5','h6','p','a','li','ul','td','span','div','html','body','header','th','strong','em','main','figcaption', 'ytd-mini-guide-renderer'];
let isNightModeOn = true;
function nightModeWebPage(webElements,booleanSwitchMode) {
webElements.forEach(selector => {
document.querySelectorAll(selector).forEach(element => {
if(!booleanSwitchMode) {
element.style.setProperty('background-color', '#13303e', 'important');
element.style.setProperty('color', '#b4ecc1', 'important');
} else {
element.style.removeProperty('background-color');
element.style.removeProperty('color');
}
})
})
}
function nightModeChangingImg() {
if(!isNightModeOn) {
MODE_DAY_NIGHT_WEB_IMG.classList.add('night-mode-button-change')
} else {
MODE_DAY_NIGHT_WEB_IMG.classList.remove('night-mode-button-change')
}
}
NIGHT_MODE_WEB_BUTTON_ELMT.addEventListener('click',() => {
isNightModeOn =!isNightModeOn;
nightModeChangingImg();
chrome.tabs.query({active: true, currentWindow: true }, (tabs)=>{
chrome.scripting.executeScript({
target: {tabId: tabs[0].id},
func: nightModeWebPage,
args: [ARRAY_WEB_ELEMENTS, isNightModeOn]
})
})
})