-
Notifications
You must be signed in to change notification settings - Fork 4
/
popup.js
41 lines (36 loc) · 1.4 KB
/
popup.js
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
document.addEventListener('DOMContentLoaded', () => {
const toggleButton = document.getElementById('toggleButton');
const statusElement = document.getElementById('status');
const buttonText = document.getElementById('buttonText');
// Load initial state from storage
chrome.storage.local.get(["extensionActive"], function (result) {
const isActive = result.extensionActive || false;
updateUI(isActive);
});
// Add event listener for toggle button
toggleButton.addEventListener('click', async function () {
chrome.storage.local.get(["extensionActive"], function (result) {
const newState = !result.extensionActive;
chrome.storage.local.set({ extensionActive: newState });
updateUI(newState);
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.reload(tabs[0].id);
});
});
});
function updateUI(isActive) {
if (isActive) {
toggleButton.classList.add('active');
buttonText.textContent = 'Turn Off';
statusElement.textContent = 'ON';
statusElement.classList.add('on');
document.querySelector('.icon').textContent = '🛑';
} else {
toggleButton.classList.remove('active');
buttonText.textContent = 'Turn On';
statusElement.textContent = 'OFF';
statusElement.classList.remove('on');
document.querySelector('.icon').textContent = '✅';
}
}
});