-
Notifications
You must be signed in to change notification settings - Fork 0
/
style.js
55 lines (45 loc) · 1.71 KB
/
style.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
const style = document.documentElement.style;
window.addEventListener('load', onWindowLoad);
chrome.storage.local.get(storedVariables, (result) =>{
style.setProperty("--background", `url(${result.bgImg})`);
setBGColor(result.bgColor);
style.setProperty("--opacity", result.opacity / 100);
storedVariables.forEach(variable => {
if(variable === 'bgImg' || variable === 'bgColor' || variable === 'opacity' || variable === 'showLogo' || variable === 'showCaptions' || variable === 'unlockZoom')
return;
style.setProperty(`--${variable}`, result[variable])
});
});
function onWindowLoad(){
createLogo();
installCaptions();
}
function setBGColor(hex){
var r = hex.substring(1,3);
var g = hex.substring(3,5);
var b = hex.substring(5,7);
style.setProperty("--bgR", parseInt(r, 16));
style.setProperty("--bgG", parseInt(g, 16));
style.setProperty("--bgB", parseInt(b, 16));
}
function createLogo(){
chrome.storage.local.get(['showLogo'], function(result){
if(result.showLogo == true){
var tepe = document.getElementsByClassName("tepe")[0];
var img = document.createElement('img');
img.src = chrome.runtime.getURL("icons/icon128.png");
img.id = "logo";
tepe.appendChild(img);
}
});
}
function installCaptions(){
chrome.storage.local.get(['showCaptions'], function(result){
if(result.showCaptions == true){
console.log(`[${extensionName}] - Creating lesson names.`)
var script = document.createElement('script');
script.src = chrome.runtime.getURL("captions.js");
document.body.appendChild(script);
}
});
}