-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-awards.js
46 lines (41 loc) · 2.39 KB
/
no-awards.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
console.log(`
███╗ ██╗ ██████╗ █████╗ ██╗ ██╗ █████╗ ██████╗ ██████╗ ███████╗
████╗ ██║██╔═══██╗ ██╔══██╗██║ ██║██╔══██╗██╔══██╗██╔══██╗██╔════╝
██╔██╗ ██║██║ ██║ ███████║██║ █╗ ██║███████║██║ ██║██║ ██║███████╗
██║╚██╗██║██║ ██║ ██╔══██║██║███╗██║██╔══██║██║ ██║██║ ██║╚════██║
██║ ╚████║╚██████╔╝██╗██║ ██║╚███╔███╔╝██║ ██║██████╔╝██████╔╝███████║
╚═╝ ╚═══╝ ╚═════╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚══════╝
Thanks for using No Awards For Reddit extension! Visit https://github.com/datguyducky/no-awards-fr for source-code
`);
// because Reddit uses infinite scroll we need to hide awards as the user scrolls, and for that we use MutationObserver
const targetNode = document.body;
const config = {
attributes: false,
childList: true,
subtree: true,
};
// Callback function to execute when mutations are observed
const callback = (mutationsList, observer) => {
// Award button on post - uses shadowRoot so some JS was needed
const shredditPosts = document.querySelectorAll('shreddit-post');
shredditPosts.forEach(post => {
if (post.shadowRoot) {
const awardButtons = post.shadowRoot.querySelectorAll('award-button');
awardButtons.forEach(button => {
button.style.display = 'none';
});
}
});
// Award button on post when viewing a feed (Popular tab for example or on a subreddit)
const feedPosts = document.querySelectorAll('shreddit-feed');
feedPosts.forEach(post => {
if (post.shadowRoot) {
const awardButtons = post.shadowRoot.querySelectorAll('award-button');
awardButtons.forEach(button => {
button.style.display = 'none';
});
}
});
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);