-
Notifications
You must be signed in to change notification settings - Fork 0
/
content-script.js
55 lines (46 loc) · 1.38 KB
/
content-script.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
"use strict";
// uncomment to debug
console.log = function() {}
var blocklist = []
chrome.storage.local.get('blindFilterText', (result) => {
console.log('Value currently is ' + result.blindFilterText);
blocklist = result.blindFilterText?.split('\n').filter((a) => a.length > 0) || []
});
function doWork(node) {
if (typeof node.getElementsByClassName !== 'function') {
return
}
if (location.href.endsWith('user/history')) {
return
}
let a = node.getElementsByClassName('h_tit')
for (let b of a) {
for (let c of blocklist) {
if (b.innerHTML.toLowerCase().includes(c)) {
console.log('blocking element that has ' + c)
b.parentElement.parentElement.parentElement.remove()
break
}
}
}
}
doWork(document)
var observer = new MutationObserver(function (mutations) {
console.log('detected mutation')
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
doWork(node.getRootNode())
}
}
})
observer.observe(document.documentElement, {
subtree: true,
childList: true,
characterData: true,
attribute: true
});
chrome.runtime.onMessage.addListener(async text => {
console.log("received " + text)
blocklist = text.split('\n').filter((a) => a.length > 0)
console.log("blocklist: ", blocklist)
});