-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
52 lines (47 loc) · 1.38 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
var defaultRgx = ["http://*/*", "https://*/*"].join('\n')
var regexpesarray = [];
function updateRegexpes(save)
{
browser.storage.local.get("regstr", function(res) {
var regstr = (res.regstr || defaultRgx);
regexpesarray = [];
var regexpesarray = regstr.split("\n")
console.log(regexpesarray)
browser.webRequest.onHeadersReceived.removeListener(setHeader)
browser.webRequest.onHeadersReceived.addListener(setHeader,
{urls : regexpesarray},
["blocking", "responseHeaders"]
);
});
}
function setHeader(e) {
for (var header of e.responseHeaders) {
if (header.name.toLowerCase() === "access-control-allow-origin") {
header.value = "*";
}
}
var myHeader = {
name: "Access-Control-Allow-Origin",
value: "*"
};
e.responseHeaders.push(myHeader);
return {responseHeaders: e.responseHeaders};
}
// Listen for onHeaderReceived for the target page.
// Set "blocking" and "responseHeaders".
updateRegexpes();
console.log("Loaded Access-Control-Allow-Origin")
var portFromCS;
function connected(p) {
portFromCS = p;
//portFromCS.postMessage({greeting: "hi there content script!"});
portFromCS.onMessage.addListener(function(m) {
if(m.updateRegexpes)
{
browser.storage.local.set({"regstr":m.updateRegexpes}, function(res) {
updateRegexpes();
});
}
});
}
browser.runtime.onConnect.addListener(connected);