-
Notifications
You must be signed in to change notification settings - Fork 7
/
remove.js
52 lines (38 loc) · 1.7 KB
/
remove.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
function deleteElements(selector) {
// in case the content script was injected after the page is partially loaded
doDelete(document.querySelectorAll(selector));
var mo = new MutationObserver(process);
mo.observe(document, {subtree:true, childList:true});
document.addEventListener('DOMContentLoaded', function() { mo.disconnect() });
function process(mutations) {
for (var i = 0; i < mutations.length; i++) {
var nodes = mutations[i].addedNodes;
for (var j = 0; j < nodes.length; j++) {
var n = nodes[j];
if (n.nodeType != 1) // only process Node.ELEMENT_NODE
continue;
doDelete(n.matches(selector) ? [n] : n.querySelectorAll(selector));
}
}
}
function doDelete(nodes) {
[].forEach.call(nodes, function(node) {
node.remove()
chrome.runtime.sendMessage({site: window.location.href}, function(){
});
});
}
}
chrome.storage.sync.get('block', function(res){
if(res.block){
deleteElements('script[src="https://coin-hive.com/lib/coinhive.min.js"]','script[src="coinhive.min.js"]','script[src="https://coinhive.com/lib/coinhive.min.js"]')
}else{
}
});
chrome.storage.onChanged.addListener(function(changes, namespace) {
chrome.storage.sync.get('block', function(res){
if(res.block){
deleteElements('script[src="https://coin-hive.com/lib/coinhive.min.js"]','script[src="coinhive.min.js"]','script[src="https://coinhive.com/lib/coinhive.min.js"]')
}
});
});