This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content-script.js
78 lines (64 loc) · 1.62 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
68
69
70
71
72
73
74
75
76
77
78
function hideElements() {
if (!chrome.runtime?.id) {
return;
}
const isMedium = document.querySelector(
'head meta[property="og:site_name"][content="medium" i]'
);
if (!isMedium) {
return;
}
const mainContent = document.getElementsByTagName("main")[0];
if (!mainContent) {
return;
}
const footer = document.getElementsByTagName("footer")[0];
const floatingActionBar = footer.nextElementSibling.nextElementSibling;
chrome.storage.sync.get(null, function (preferences) {
const rightSidebar = mainContent.nextSibling;
if (rightSidebar) {
rightSidebar.style.display = preferences.hideRightSidebar
? "none"
: "block";
}
if (floatingActionBar) {
floatingActionBar.style.display = preferences.hideFloatingActionBar
? "none"
: "";
}
});
}
function setupObserver() {
const observer = new MutationObserver((mutations) => {
let realMutationCount = 0;
mutations.forEach((mutation) => {
const oldValue = mutation.oldValue;
const newValue = mutation.target.textContent;
if (oldValue !== newValue) {
realMutationCount++;
}
});
if (realMutationCount > 0) {
hideElements();
}
});
const subject = document.getElementById("root");
if (subject) {
observer.observe(subject, {
characterDataOldValue: true,
subtree: true,
childList: true,
characterData: true,
});
}
}
function main() {
hideElements();
setupObserver();
}
chrome.runtime.onMessage.addListener(function (request) {
if (request.message === "reload") {
hideElements();
}
});
main();