-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
executable file
·66 lines (55 loc) · 1.27 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
54
55
56
57
58
59
60
61
62
63
64
65
66
var targetUrl = ["*://*.youtube.com/*", "*://i.ytimg.com/*", "*://yt3.ggpht.com/*"]
var portFromCS;
var settings;
function connected(p) {
portFromCS = p;
}
browser.runtime.onConnect.addListener(connected);
function onError(e)
{
console.log(e)
}
function saveSettings(s)
{
settings = s.settings
}
function postMessage(s)
{
settings = s.settings
portFromCS.postMessage({settings: settings})
}
function sendMessage(e) {
if(portFromCS)
{
const gettingSettings = browser.storage.local.get();
gettingSettings.then(postMessage, onError);
}
return {};
}
function cancelRequest(e)
{
if(settings.youtube)
{
if(portFromCS)
{
const gettingSettings = browser.storage.local.get();
gettingSettings.then(postMessage, onError);
}
return {cancel: true}
}
else
return {}
}
browser.webRequest.onBeforeRequest.addListener(
cancelRequest,
{urls: ["*://*.googlevideo.com/*", "*://*.ytimg.com/*", "*://yt3.ggpht.com/*"]},
["blocking"]
);
browser.webRequest.onCompleted.addListener(
sendMessage,
{urls: ["*://*.youtube.com/*"]},
[]
);
const getSettings = browser.storage.local.get();
getSettings.then(saveSettings, onError);
console.log("BACKGROUND WORKING")