nostr-links/background.js

28 lines
918 B
JavaScript

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status !== 'complete') {
chrome.action.disable(tabId);
chrome.storage.local.remove(`nl_tab_${tabId}`);
return;
}
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'showNostrLinksPageAction' && sender.tab?.id) {
const tabLinks = { [`nl_tab_${sender.tab.id}`]: message.links };
chrome.storage.local.set(tabLinks, () => {
chrome.action.enable(sender.tab.id);
});
}
if (message.action === 'getNostrLinks' && message.tabId) {
chrome.storage.local.get(`nl_tab_${message.tabId}`, (result) => {
sendResponse({ links: result[`nl_tab_${message.tabId}`] || [] });
});
return true; // Keep message channel open for async response
}
});
chrome.tabs.onRemoved.addListener((tabId) => {
chrome.storage.local.remove(`nl_tab_${tabId}`);
});