-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
36 lines (32 loc) · 1.12 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
const toggleValue = localStorage.getItem("toggleValue");
let twitterScriptObserver = null;
const removeTweetViews = () => {
const views = document.querySelectorAll('[aria-label*="estatísticas do Tweet"]');
const viewsEn = document.querySelectorAll('[aria-label*="Tweet analytics"]');
views.forEach(view => view.parentElement.remove());
viewsEn.forEach(view => view.parentElement.remove());
};
const startTwitterScript = () => {
console.log("Twitter script started");
removeTweetViews();
twitterScriptObserver = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => removeTweetViews());
});
});
localStorage.setItem("toggleValue", "checked");
twitterScriptObserver.observe(document.body, { childList: true, subtree: true });
};
const stopTwitterScript = () => {
console.log("Twitter script stopped");
localStorage.setItem("toggleValue", "unchecked");
if (twitterScriptObserver) {
twitterScriptObserver.disconnect();
twitterScriptObserver = null;
}
};
if (toggleValue === "checked") {
startTwitterScript();
} else {
stopTwitterScript();
}