-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
52 lines (45 loc) · 1.52 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
42
43
44
45
46
47
48
49
50
51
52
// Comment: Functionality to disable the extension
document.addEventListener('DOMContentLoaded', function() {
var toggleButton = document.getElementById('disableButton');
// Event listener for toggle button click
toggleButton.addEventListener('click', function() {
// Get the current state of the extension
chrome.storage.sync.get('extensionEnabled', function(result) {
// Toggle the enabled state
var enabled = !result.extensionEnabled;
// Save the updated state
chrome.storage.sync.set({ extensionEnabled: enabled }, function() {
// Update the extension icon based on the new state
updateIcon(enabled);
});
});
});
// Call updateIcon() initially to set the icon based on the current storage value
chrome.storage.sync.get('extensionEnabled', function(result) {
var enabled = result.extensionEnabled;
// Update icon and toggle button state based on storage value
if (enabled === true) {
updateIcon(true);
toggleButton.checked = enabled;
} else {
updateIcon(false);
toggleButton.checked = false;
}
});
});
// Function to update the extension icon
function updateIcon(enabled) {
var iconPath;
// Set icon path based on the state
if (enabled) {
iconPath = {
"16": "icon_enabled.png"
};
} else {
iconPath = {
"16": "icon_disabled.png"
};
}
// Set the icon
chrome.action.setIcon({ path: iconPath });
}