-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
39 lines (31 loc) · 1.1 KB
/
content.js
File metadata and controls
39 lines (31 loc) · 1.1 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
function extractFacebookIdFromComment(commentElement) {
const profileLink = commentElement.querySelector('a[href*="facebook.com"][href*="/"]');
if (profileLink) {
const url = new URL(profileLink.href);
const path = url.pathname; // e.g. /vica.sandor
const id = path.split("/")[1]; // "vica.sandor"
return id;
}
return null;
}
function hideBlacklistedCommentsById(blacklist) {
const commentBlocks = document.querySelectorAll('div[aria-label^="Comment by "]');
commentBlocks.forEach(comment => {
const fbId = extractFacebookIdFromComment(comment);
if (fbId && blacklist.includes(fbId)) {
comment.style.display = "none";
console.debug(`Comment by ID "${fbId}" hidden.`);
}
});
}
function observeCommentsById(blacklist) {
const observer = new MutationObserver(() => {
hideBlacklistedCommentsById(blacklist);
});
observer.observe(document.body, { childList: true, subtree: true });
hideBlacklistedCommentsById(blacklist);
}
chrome.storage.local.get(["blacklist"], (result) => {
const blacklist = result.blacklist || [];
observeCommentsById(blacklist);
});