document.addEventListener('DOMContentLoaded', () => { const intervalSelect = document.getElementById('refreshInterval'); const saveButton = document.getElementById('saveInterval'); // Load the saved interval from storage when the popup opens browser.storage.local.get('refreshInterval').then(result => { if (result.refreshInterval) { intervalSelect.value = result.refreshInterval / 1000; // Convert milliseconds to seconds for the dropdown } }); saveButton.addEventListener('click', () => { const selectedIntervalSeconds = parseInt(intervalSelect.value); const selectedIntervalMilliseconds = selectedIntervalSeconds * 1000; // Save the selected interval to storage browser.storage.local.set({ refreshInterval: selectedIntervalMilliseconds }).then(() => { // Send a message to the background script to update the interval browser.runtime.sendMessage({ action: 'updateInterval', interval: selectedIntervalMilliseconds }); window.close(); // Close the popup after saving }); }); });