forked from amureki/django-devbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
35 lines (30 loc) · 1013 Bytes
/
content.js
File metadata and controls
35 lines (30 loc) · 1013 Bytes
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
const STORAGE_KEY = 'django-devbar-show-bar';
let currentShowState = true;
let styleElement = null;
function injectHideCSS() {
if (!styleElement) {
styleElement = document.createElement('style');
styleElement.id = 'devbar-visibility-control';
styleElement.textContent = '#django-devbar { display: none !important; }';
(document.head || document.documentElement).appendChild(styleElement);
}
}
function removeHideCSS() {
if (styleElement?.parentNode) {
styleElement.parentNode.removeChild(styleElement);
styleElement = null;
}
}
function checkAndApply() {
chrome.storage.local.get([STORAGE_KEY], (result) => {
currentShowState = result[STORAGE_KEY] !== false;
currentShowState ? removeHideCSS() : injectHideCSS();
});
}
checkAndApply();
chrome.storage.onChanged.addListener((changes, area) => {
if (area === 'local' && changes[STORAGE_KEY]) {
currentShowState = changes[STORAGE_KEY].newValue;
currentShowState ? removeHideCSS() : injectHideCSS();
}
});