-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
27 lines (23 loc) · 861 Bytes
/
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
document.addEventListener('DOMContentLoaded', () => {
const toggleButton = document.getElementById('toggleButton');
chrome.storage.sync.get('isEnabled', (data) => {
updateButton(data.isEnabled);
});
toggleButton.addEventListener('click', () => {
chrome.storage.sync.get('isEnabled', (data) => {
const newStatus = !data.isEnabled;
chrome.storage.sync.set({ isEnabled: newStatus }, () => {
updateButton(newStatus);
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
files: ['content.js']
});
});
});
});
});
function updateButton(isEnabled) {
toggleButton.textContent = isEnabled ? 'Disable' : 'Enable';
}
});