-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwiper.js
More file actions
64 lines (52 loc) · 1.78 KB
/
Copy pathwiper.js
File metadata and controls
64 lines (52 loc) · 1.78 KB
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
/**
* Modify the search results on (Google.com) that happen to be
* from certain URLs.
* @param {Array} urls- a list of URLs to modify the results of
*/
function clearURLs(urls) {
const isBlacklistedUrl = (link) => urls.some(url => link.includes(url));
const decorateURL = (url) => `Wiper blacklisted URL: <a href="${url}">${url}</a>`;
Array.from(document.querySelectorAll('div.g'))
.filter(result => isBlacklistedUrl(result.querySelector('a').href))
.forEach(result => {result.innerHTML = decorateURL(result.querySelector('a').href)});
return true;
}
function handleBlacklistURLs(blacklist){
return clearURLs(blacklist.blacklistURLs);
}
function handleGoogleSearchResults(toggle){
if (toggle === true){
browser.runtime.sendMessage({'message': 'google.com-true'});
browser.storage.local.get('blacklistURLs')
.then(handleBlacklistURLs, reportError);
}
}
/**
* Log an error. This function might be updated in a future version
* remote error loggin.
* @param {String} err- the error
*/
function reportError(err) {
console.log(err);
}
/* global operations for every time the target page (./google./search) loads */
//document.body.style.border = "1px solid blue";
browser.storage.local.get('enabled')
.then(
(enabled) => {handleGoogleSearchResults(enabled.enabled)},
reportError);
/*
Add Listeners to changes in storage.
*/
function localStorageChangeHandler(changes) {
let changedItems = Object.keys(changes);
for (let item of changedItems){
if (item === 'enabled' && changes[item].newValue === true){
handleGoogleSearchResults(true);
}
else if (item === 'enabled' && changes[item].newValue != true){
handleGoogleSearchResults(false);
}
}
}
browser.storage.onChanged.addListener(localStorageChangeHandler);