-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
68 lines (56 loc) · 1.64 KB
/
Copy pathcontent.js
File metadata and controls
68 lines (56 loc) · 1.64 KB
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
let observer = null;
function cleanAnnotations() {
document.querySelectorAll('a[data-ignore-on-click-outside="true"]').forEach(link => {
const fragment = document.createDocumentFragment();
while (link.firstChild) {
fragment.appendChild(link.firstChild);
}
link.replaceWith(fragment);
});
document.querySelectorAll('span[tabindex="0"][style*="position:absolute"]').forEach(span => {
span.remove();
});
document.querySelectorAll('span[role="presentation"][class*="ReferentFragment"], span[class*="Highlight"][class*="ReferentFragment"]').forEach(span => {
if (span.matches('[style*="position:absolute"]')) return;
const fragment = document.createDocumentFragment();
while (span.firstChild) {
fragment.appendChild(span.firstChild);
}
span.replaceWith(fragment);
});
document.querySelectorAll('.LyricsHighlightTooltipContainer').forEach(el => {
el.remove();
});
}
function startCleaning() {
cleanAnnotations();
if (observer) observer.disconnect();
observer = new MutationObserver(() => {
requestAnimationFrame(() => {
setTimeout(cleanAnnotations, 100);
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
function stopCleaning() {
if (observer) {
observer.disconnect();
observer = null;
}
}
browser.storage.local.get(['cleanerEnabled']).then((result) => {
if (result.cleanerEnabled !== false) {
startCleaning();
}
});
browser.runtime.onMessage.addListener((message) => {
if (message.action === 'clean') {
startCleaning();
} else if (message.action === 'reload') {
stopCleaning();
location.reload();
}
});