-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
82 lines (67 loc) · 2.29 KB
/
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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// When the button is clicked, inject setPageBackgroundColor into current page
let bg_lightBlue = document.getElementById('bg-lightBlue');
let bg_black = document.getElementById('bg-black');
let bg_grey = document.getElementById('bg-grey');
let bg_white = document.getElementById('bg-white');
document.body.addEventListener('load', async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: setSavedColor,
});
})
// function setSavedColor() {
// console.log('retreiving from memory')
// chrome.storage.sync.get(['mainPageColor'], function(result) {
// document.body.style.backgroundColor = result;
// });
// }
// setSavedColor();
bg_lightBlue.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: changeToLightBlue,
});
});
function changeToLightBlue() {
chrome.storage.sync.set({mainPageColor: "lightBlue"}, () => {
});
document.body.style.backgroundColor = "lightBlue";
}
bg_black.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: changeToBlack,
});
});
function changeToBlack() {
chrome.storage.sync.set({mainPageColor: "black"}, () => {
});
document.body.style.backgroundColor = "black";
}
bg_grey.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: changeToGrey,
});
});
function changeToGrey() {
chrome.storage.sync.set({mainPageColor: "grey"}, () => {
});
document.body.style.backgroundColor = "grey";
}
bg_white.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: changeToWhite,
});
});
function changeToWhite() {
chrome.storage.sync.set({mainPageColor: "white"}, () => {
});
document.body.style.backgroundColor = "white";
}