-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathytblur.js
More file actions
30 lines (25 loc) · 1.05 KB
/
ytblur.js
File metadata and controls
30 lines (25 loc) · 1.05 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
/* ---------------------------------------------------------------------------
Blur (or unblur) every thumbnail <img> element in the document.
--------------------------------------------------------------------------- */
let blurEnabled = true; // Updated via chrome.storage
/** Apply correct filter to all current thumbnails. */
const applyBlur = () => {
document
.querySelectorAll('ytd-thumbnail img')
.forEach((img) => (img.style.filter = blurEnabled ? 'blur(10px)' : ''));
};
/** Watch for new thumbnails (YouTube is an SPA). */
const observer = new MutationObserver(applyBlur);
observer.observe(document.body, { childList: true, subtree: true });
/* ---------- Initialise from storage ---------- */
chrome.storage.sync.get({ blurEnabled: true }, (data) => {
blurEnabled = data.blurEnabled;
applyBlur();
});
/* ---------- React instantly to popup changes ---------- */
chrome.storage.onChanged.addListener((changes, area) => {
if (area === 'sync' && changes.blurEnabled) {
blurEnabled = changes.blurEnabled.newValue;
applyBlur();
}
});