|
1 | | -((() => { |
2 | | - 'use strict'; |
| 1 | +const STORAGE_KEY = 'django-devbar-show-bar'; |
| 2 | +let currentShowState = true; |
| 3 | +let styleElement = null; |
3 | 4 |
|
4 | | - if (typeof chrome === 'undefined' || !chrome.storage) { |
5 | | - return; |
| 5 | +function injectHideCSS() { |
| 6 | + if (!styleElement) { |
| 7 | + styleElement = document.createElement('style'); |
| 8 | + styleElement.id = 'devbar-visibility-control'; |
| 9 | + styleElement.textContent = '#django-devbar { display: none !important; }'; |
| 10 | + (document.head || document.documentElement).appendChild(styleElement); |
6 | 11 | } |
| 12 | +} |
7 | 13 |
|
8 | | - const STORAGE_KEY = 'django-devbar-show-bar'; |
9 | | - let currentShowState = true; |
10 | | - let styleElement = null; |
11 | | - |
12 | | - function injectHideCSS() { |
13 | | - if (!styleElement) { |
14 | | - styleElement = document.createElement('style'); |
15 | | - styleElement.id = 'devbar-visibility-control'; |
16 | | - styleElement.textContent = '#django-devbar { display: none !important; }'; |
17 | | - (document.head || document.documentElement).appendChild(styleElement); |
18 | | - } |
19 | | - } |
20 | | - |
21 | | - function removeHideCSS() { |
22 | | - if (styleElement?.parentNode) { |
23 | | - styleElement.parentNode.removeChild(styleElement); |
24 | | - styleElement = null; |
25 | | - } |
| 14 | +function removeHideCSS() { |
| 15 | + if (styleElement?.parentNode) { |
| 16 | + styleElement.parentNode.removeChild(styleElement); |
| 17 | + styleElement = null; |
26 | 18 | } |
| 19 | +} |
27 | 20 |
|
28 | | - function checkAndApply() { |
29 | | - chrome.storage.local.get([STORAGE_KEY], (result) => { |
30 | | - currentShowState = result[STORAGE_KEY] !== false; |
31 | | - currentShowState ? removeHideCSS() : injectHideCSS(); |
32 | | - }); |
33 | | - } |
| 21 | +function checkAndApply() { |
| 22 | + chrome.storage.local.get([STORAGE_KEY], (result) => { |
| 23 | + currentShowState = result[STORAGE_KEY] !== false; |
| 24 | + currentShowState ? removeHideCSS() : injectHideCSS(); |
| 25 | + }); |
| 26 | +} |
34 | 27 |
|
35 | | - checkAndApply(); |
| 28 | +checkAndApply(); |
36 | 29 |
|
37 | | - chrome.storage.onChanged.addListener((changes, area) => { |
38 | | - if (area === 'local' && changes[STORAGE_KEY]) { |
39 | | - currentShowState = changes[STORAGE_KEY].newValue; |
40 | | - currentShowState ? removeHideCSS() : injectHideCSS(); |
41 | | - } |
42 | | - }); |
43 | | -}))(); |
| 30 | +chrome.storage.onChanged.addListener((changes, area) => { |
| 31 | + if (area === 'local' && changes[STORAGE_KEY]) { |
| 32 | + currentShowState = changes[STORAGE_KEY].newValue; |
| 33 | + currentShowState ? removeHideCSS() : injectHideCSS(); |
| 34 | + } |
| 35 | +}); |
0 commit comments