-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
95 lines (84 loc) · 3.33 KB
/
popup.js
File metadata and controls
95 lines (84 loc) · 3.33 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Function to update the UI based on the stored state
function updatePopupUI(state) {
const toggleButton = document.getElementById("toggleButton");
toggleButton.textContent = state ? "Play Extension" : "Pause Extension";
}
document.addEventListener("DOMContentLoaded", function () {
document.getElementById('optionsButton').addEventListener('click', function() {
chrome.tabs.create({ url: 'options.html' });
});
const groupContainer = document.getElementById('groupContainer');
chrome.storage.local.get('groups', function(data) {
const groups = data.groups || [];
// Create buttons for each group
groups.forEach(function(group) {
const button = document.createElement('button');
button.classList.add('groupButton');
button.textContent = group;
chrome.storage.local.get('selectedGroup', function(data) {
groupName = data.selectedGroup;
if (button.textContent === groupName) {
button.classList.add('selected');
}
});
button.addEventListener('click', function() {
// Remove 'selectec' class from all buttons
document.querySelectorAll('.groupButton').forEach(btn => {
btn.classList.remove('selected');
});
// Add selected class to the clicked button
this.classList.add('selected');
console.log('Group selected: ', group);
chrome.storage.local.set({ selectedGroup: group }, function () {
console.log("Selected group changed: ", group);
});
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.reload(tabs[0].id);
});
});
groupContainer.appendChild(button);
});
});
const toggleButton = document.getElementById("toggleButton");
if (toggleButton.textContent === "Pause Extension") {
toggleButton.classList.remove('playing');
toggleButton.classList.add('paused');
} else if (toggleButton.textContent === "Play Extension") {
toggleButton.classList.remove('paused');
toggleButton.classList.add('playing');
}
// Load the initial state from chrome.storage.local and update de UI
chrome.storage.local.get("extensionPaused", function (data) {
const extensionPaused = data.extensionPaused;
updatePopupUI(extensionPaused);
});
// Listen for button click to toggle the extension state
toggleButton.addEventListener("click", function () {
chrome.storage.local.get("extensionPaused", function (data) {
const extensionPaused = data.extensionPaused;
const newExtensionPaused = !extensionPaused;
chrome.storage.local.set(
{ extensionPaused: newExtensionPaused },
function () {
console.log(
"Extension state changed:",
newExtensionPaused ? "paused" : "playing"
);
// Update the UI
updatePopupUI(newExtensionPaused);
}
);
});
// Reload the current tab
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.reload(tabs[0].id);
});
if (toggleButton.textContent === "Pause Extension") {
toggleButton.classList.remove('playing');
toggleButton.classList.add('paused');
} else if (toggleButton.textContent === "Play Extension") {
toggleButton.classList.remove('paused');
toggleButton.classList.add('playing');
}
});
});