-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
69 lines (56 loc) · 1.64 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
67
68
69
var rule1 = {
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: 'www.google.com' },
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
};
var rule2 = {
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: 'www.apple.com' },
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
};
var rules = [rule1, rule2];
var siteHosts = [];
var siteRules = [];
function getSites()
{
const sitesJsonUrl = chrome.runtime.getURL('Allsides-Scraper/biasRatings.json');
fetch(sitesJsonUrl)
.then((response) => response.json())
.then((json) => extractInformation(json));
};
// Adds list of site host names to global variable siteHosts
function extractInformation(x)
{
var tempRule;
for (var y in x)
{
tempRule = {
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { pathContains : y },
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
};
siteRules.push(tempRule);
siteHosts.push(y);
}
console.log(siteRules);
console.log(rules);
};
chrome.runtime.onInstalled.addListener(function () {
chrome.storage.sync.set({ color: '#3aa757' }, function () {
console.log("The color is green.");
});
getSites();
chrome.declarativeContent.onPageChanged.removeRules(undefined, function () {
console.log("wat");
chrome.declarativeContent.onPageChanged.addRules(siteRules);
});
});