-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
47 lines (39 loc) · 1.78 KB
/
options.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
document.addEventListener('DOMContentLoaded', function() {
const optionsForm = document.getElementById('optionsForm');
const safeWebsiteInput = document.getElementById('safeWebsiteInput');
const confirmationMessage = document.getElementById('confirmationMessage');
// Load the saved safe website URL from storage
chrome.storage.sync.get(['safeWebsite'], function(result) {
if (result.safeWebsite) {
safeWebsiteInput.value = result.safeWebsite;
} else {
console.error('No safe website URL found in storage.');
}
});
// Save the safe website URL to storage when the form is submitted
optionsForm.addEventListener('submit', function(event) {
event.preventDefault();
// Get the entered safe website URL
const safeWebsite = safeWebsiteInput.value;
// Save the safe website URL to storage
chrome.storage.sync.set({ safeWebsite: safeWebsite }, function() {
console.log('Safe website URL saved:', safeWebsite);
// Send a message to the background script indicating that the safe website URL has been updated
chrome.runtime.sendMessage({ action: 'safeWebsiteUpdated', url: safeWebsite });
// Show confirmation message
confirmationMessage.textContent = 'Safe website URL saved!';
confirmationMessage.style.display = 'block';
// Clear the confirmation message after 3 seconds
setTimeout(function() {
confirmationMessage.style.display = 'none';
}, 3000);
});
});
// Automatically save the safe website URL when the input field value changes
safeWebsiteInput.addEventListener('input', function() {
const safeWebsite = safeWebsiteInput.value;
chrome.storage.sync.set({ safeWebsite: safeWebsite }, function() {
console.log('Safe website URL updated:', safeWebsite);
});
});
});