-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent-script.js
67 lines (52 loc) · 1.91 KB
/
content-script.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
66
67
async function app(){
let storage = browser.storage.local;
// get list of blocked users from storage
let blockedUsers = await storage.get('blockedUsers');
blockedUsers = blockedUsers.blockedUsers
browser.storage.onChanged.addListener((changes, area) => {
blockedUsers = changes.blockedUsers.newValue;
});
const observer = new MutationObserver(removeNewTweetsAddedToDOM);
observer.observe(document.body, { childList: true, subtree: true });
function removePost(user, post) {
const { username, shouldRemoveTweet, shouldRemoveRetweet } = user;
// (*)
if (!post.innerText.includes(username)) return;
// if post is from user...
const isRetweet = post.innerText.includes(username + 'Retweet');
const isTweet = !isRetweet;
if ((shouldRemoveTweet && isTweet) || (shouldRemoveRetweet && isRetweet)) {
post.parentElement.parentElement.parentElement.style.display = 'none';
}
// (**)
/*
the code from (*) to (**) can be replaced with
if( (removeTweet && post.innerText.includes(username)) || (removeRetweet && post.innerText.includes(username+ ' Retweeted')) ){
post.parentElement.parentElement.parentElement.style.display =
'none';
}
*/
}
/* TODO add functionality to remove promoted tweets
*/
// function removeTweetsAlreadyInDOM(){
// feed.children.forEach(childElem => {
// if()
// })
// }
function removeNewTweetsAddedToDOM(mutations) {
mutations.forEach((mutation) => {
const { addedNodes } = mutation;
if (!addedNodes.length) return;
// if there are added nodes...
for (const node of addedNodes) {
if (node.tagName && node.querySelector('article')) {
const post = node.querySelector('article');
console.log(post);
blockedUsers.forEach((user) => removePost(user, post));
}
}
});
}
}
app()