-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
38 lines (32 loc) · 1.35 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
document.addEventListener('DOMContentLoaded', () => {
const textarea = document.getElementById('selectors');
const saveButton = document.getElementById('save');
const status = document.getElementById('status');
const selectorsList = document.getElementById('selectors-list');
// Load existing selectors
chrome.storage.sync.get('selectors', (data) => {
const selectors = data.selectors || [];
textarea.value = selectors.join('\n');
updateSelectorsList(selectors);
});
// Save button click event
saveButton.addEventListener('click', () => {
const selectors = textarea.value.split('\n').map(s => s.trim()).filter(s => s.length > 0);
// Simple validation for selectors
if (selectors.length === 0) {
status.textContent = 'Please enter at least one selector.';
status.style.color = 'red';
return;
}
chrome.storage.sync.set({ selectors: selectors }, () => {
status.textContent = 'Selectors saved!';
status.style.color = '#28a745';
updateSelectorsList(selectors);
setTimeout(() => status.textContent = '', 2000);
});
});
// Update the list of selectors in the popup
function updateSelectorsList(selectors) {
selectorsList.innerHTML = selectors.map(selector => `<li>${selector}</li>`).join('');
}
});