-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_scripts.js
More file actions
69 lines (50 loc) · 2.03 KB
/
content_scripts.js
File metadata and controls
69 lines (50 loc) · 2.03 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
function searchBlockTerms() {
console.log("searchBlockTerms is being executed");
const videoTitles = [...document.querySelectorAll('#video-title.style-scope.ytd-rich-grid-media')].map(x => x.innerText);
//console.log(videoTitles);
browser.runtime.sendMessage({
message: "lol"
}).then((message) => {
let timer_index = 1;
videoTitles.forEach((titleElement, index) => {
const titleText = titleElement.toLowerCase();
//console.log(message);
const list = message ? JSON.parse(message) : [];
const foundWords = list.filter(word => titleText.includes(word.toLowerCase()));
const video_selector = "div#menu.style-scope.ytd-rich-grid-media>ytd-menu-renderer.style-scope.ytd-rich-grid-media>yt-icon-button#button.dropdown-trigger.style-scope.ytd-menu-renderer";
const menubutton_selector = "tp-yt-paper-item.style-scope.ytd-menu-service-item-renderer";
if (foundWords.length > 0) {
browser.runtime.sendMessage({
message: "need indexes pls",
data: index
}).then((response) => {
//console.log("response " + response);
//response is boolean. Checks if video with given index has already been blocked to avoid double blocking
if(response){
console.log(`Title: ${titleText}`);
console.log(`Found words: ${foundWords.join(", ")}`);
setTimeout(() => {
let video = document.querySelectorAll(video_selector);
//console.log(video);
video[index].children[0].click();
//console.log("selected video menu");
setTimeout(() => {
document.querySelectorAll(menubutton_selector)[4].click();
console.log("removed video");
}, 400);
}, 500 * (timer_index++));
}
});
}
});
});
}
setInterval(() => {
searchBlockTerms();
}, 5000);
window.addEventListener('beforeunload', function() {
browser.runtime.sendMessage({
message: "clear indexes"
})
}
)