-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
54 lines (46 loc) · 1.77 KB
/
Copy pathpopup.js
File metadata and controls
54 lines (46 loc) · 1.77 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
document.addEventListener('DOMContentLoaded', () => {
const toggle = document.getElementById('toggle-active');
const counterEl = document.getElementById('counter');
const resetBtn = document.getElementById('btn-reset');
const debugBtn = document.getElementById('btn-debug');
const versionEl = document.getElementById('ext-version');
versionEl.textContent = 'v' + chrome.runtime.getManifest().version;
document.querySelectorAll('[data-i18n]').forEach(el => {
const key = el.getAttribute('data-i18n');
const msg = chrome.i18n.getMessage(key);
if (msg) {
el.textContent = msg;
}
});
chrome.storage.local.get({ active: true, adCount: 0, debug: false }, (data) => {
toggle.checked = data.active;
counterEl.textContent = data.adCount;
if (data.debug) debugBtn.classList.add('active');
});
toggle.addEventListener('change', () => {
chrome.storage.local.set({ active: toggle.checked });
});
resetBtn.addEventListener('click', () => {
chrome.storage.local.set({ adCount: 0 });
});
debugBtn.addEventListener('click', () => {
const isActive = debugBtn.classList.toggle('active');
chrome.storage.local.set({ debug: isActive });
});
const animations = [
'anim-bounce', 'anim-spin3d', 'anim-pulse', 'anim-shake', 'anim-flip',
'anim-zoomin', 'anim-slidedown', 'anim-rubberband', 'anim-flash', 'anim-swing'
];
const randomAnim = animations[Math.floor(Math.random() * animations.length)];
counterEl.classList.add(randomAnim);
chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'local') {
if (changes.adCount) {
counterEl.textContent = changes.adCount.newValue;
}
if (changes.active) {
toggle.checked = changes.active.newValue;
}
}
});
});