-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
executable file
·53 lines (48 loc) · 2.09 KB
/
background.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
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && /^http/.test(tab.url)) {
chrome.storage.sync.get(["themeSelected", "blockSubscribeButton", "addLyricsButton"], function (obj) {
let themeSelected = obj ? obj.themeSelected : "default.css";
let blockSubscribeButton = obj && typeof obj.blockSubscribeButton === 'boolean' ? obj.blockSubscribeButton : true;
let blockSubscribeModal = obj && typeof obj.blockSubscribeModal === 'boolean' ? obj.blockSubscribeModal : true;
let addLyricsButton = obj && typeof obj.addLyricsButton === 'boolean' ? obj.addLyricsButton : true;
if (blockSubscribeButton == true) {
chrome.scripting.insertCSS({
target: { tabId: tabId },
files: [`./blockSubscribeButton.css`]
})
.then(() => {
console.log("Subscribe button removed");
})
.catch(err => console.log(err));
}
if (blockSubscribeModal == true) {
chrome.scripting.insertCSS({
target: { tabId: tabId },
files: [`./blockSubscribeModal.css`]
})
.then(() => {
console.log("Subscribe modal removed");
})
.catch(err => console.log(err));
}
if (addLyricsButton == true) {
chrome.scripting.executeScript({
target: {tabId: tabId},
files: ['addLyrics.js'],
})
.then(() => {
console.log("Lyrics button added");
})
.catch(err => console.log(err));
}
chrome.scripting.insertCSS({
target: { tabId: tabId },
files: [`./themes/${themeSelected}`]
})
.then(() => {
console.log("Theme injected");
})
.catch(err => console.log(err));
});
}
});