let currentInterval = 15000; // Default interval (15 seconds) // Load the saved interval when the background script starts browser.storage.local.get('refreshInterval').then(result => { currentInterval = result.refreshInterval || currentInterval; notifyContentScript(currentInterval); }); // Listen for messages from the popup to update the interval browser.runtime.onMessage.addListener((request, sender, sendResponse) => { if (request.action === 'updateInterval') { currentInterval = request.interval; browser.storage.local.set({ refreshInterval: currentInterval }); // Ensure it's saved notifyContentScript(currentInterval); } }); function notifyContentScript(interval) { browser.tabs.query({ url: 'https://bsky.app/' }).then(tabs => { tabs.forEach(tab => { browser.tabs.sendMessage(tab.id, { action: 'setInterval', interval: interval }); }); }); }