-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
52 lines (42 loc) · 1.57 KB
/
content.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
let keywords = [];
function filterVideos() {
const videoElements = document.querySelectorAll('ytd-rich-item-renderer, ytd-video-renderer');
videoElements.forEach(video => {
const titleElement = video.querySelector('#video-title');
const channelElement = video.querySelector('#text.ytd-channel-name');
const descriptionElement = video.querySelector('#description-text');
if (titleElement || channelElement || descriptionElement) {
const title = titleElement ? titleElement.textContent.toLowerCase() : '';
const channel = channelElement ? channelElement.textContent.toLowerCase() : '';
const description = descriptionElement ? descriptionElement.textContent.toLowerCase() : '';
const contentToCheck = title + ' ' + channel + ' ' + description;
const shouldUnblur = keywords.some(keyword =>
contentToCheck.includes(keyword.toLowerCase())
);
video.classList.toggle('blur-video', !shouldUnblur);
}
});
}
function onMutations(mutations) {
for (let mutation of mutations) {
if (mutation.type === 'childList') {
filterVideos();
}
}
}
chrome.storage.sync.get('keywords', function(data) {
if (data.keywords) {
keywords = data.keywords;
filterVideos();
}
});
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === "updateKeywords") {
keywords = request.keywords;
filterVideos();
}
});
const observer = new MutationObserver(onMutations);
observer.observe(document.body, { childList: true, subtree: true });
// Initial filter
filterVideos();