-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentScript.js
65 lines (60 loc) · 2.3 KB
/
ContentScript.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
(function() {
"use strict";
var names = [];
chrome.storage.sync.get("names", function(e) {
console.log(e);
names = e.names || [];
});
var listenForAllComments = function(e) {
if (e.target.querySelector) {
var frame = document.getElementById("live-chat-iframe").contentDocument,
allcomments = frame.querySelector('#contents > yt-live-chat-renderer');
var blockbutton = frame.querySelector('ytd-menu-service-item-renderer');
if (allcomments) {
allcomments.addEventListener('DOMNodeInserted', function(e) {
if (e.target.nodeType === 3) {
var author = e.target.parentElement.previousElementSibling.innerText,
parent = e.target.parentElement.parentElement,
menu = parent.nextElementSibling;
//console.log(author,e.target.parentElement.innerText);
menu.addEventListener('click', function(f) {
//console.log(author);
//console.dir(blockbutton);
blockbutton = frame.querySelector('ytd-menu-service-item-renderer');
if (blockbutton) {
blockbutton.author = author;
}
var bbf = function(g) {
console.log(blockbutton.author);
if (!names.some(function(f) {
return f === blockbutton.author;
})) {
names.push(blockbutton.author);
chrome.storage.sync.set({
"names": names
});
}
blockbutton.removeEventListener('click', bbf);
};
blockbutton.addEventListener('click', bbf);
});
if (author && names.some(function(f) {
return f === author;
})) {
console.log("blocked " + author);
parent.parentElement.style.display = 'none';
}
//console.dir(e);
}
});
removeEventListener("DOMNodeInserted", listenForAllComments);
}
}
};
addEventListener('DOMNodeInserted', listenForAllComments);
chrome.storage.onChanged.addListener(function(changes, area) {
if (area === "sync") {
names = changes.names.newValue;
}
});
})();