This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
53 lines (43 loc) · 1.46 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
53
function sbIsPoster(postEl, ignoredUsers) {
return ignoredUsers.includes(postEl.querySelector(".poster h4 a").innerText);
}
function sbIsQuoted(postEl, ignoredUsers) {
let quoteHeaders = [];
postEl
.querySelectorAll("cite a")
.forEach((el) => quoteHeaders.push(el.innerText));
if (!quoteHeaders.length) return false;
return quoteHeaders.some((header) =>
ignoredUsers.some((user) => header.includes(user))
);
}
function sbIsMarkedPost(postEl, ignoredUsers) {
return sbIsPoster(postEl, ignoredUsers) || sbIsQuoted(postEl, ignoredUsers);
}
function sbGetPosts() {
const topicPosts = document.querySelectorAll(".post_wrapper");
const bestOfPosts = document.querySelectorAll(".core_posts");
return { topic: topicPosts, best: bestOfPosts };
}
function sbRun(ignoredUsers = [], blur) {
const { topic, best } = sbGetPosts();
topic.forEach((post) => {
if (sbIsMarkedPost(post, ignoredUsers)) {
post.parentElement.classList.add(
blur ? "sb-ignore-user-blur" : "sb-ignore-user-hide"
);
}
});
best.forEach((post) => {
if (sbIsMarkedPost(post, ignoredUsers)) {
post.classList.add(blur ? "sb-ignore-user-blur" : "sb-ignore-user-hide");
}
});
}
chrome.storage.local.get("settings", (result) => {
const { sb_on, sb_ignoredUsers, sb_blur } = result.settings || {};
const ignoredUsers = sb_ignoredUsers.split(",");
if (sb_on && ignoredUsers.length && !!ignoredUsers[0]) {
sbRun(ignoredUsers, sb_blur);
}
});