29 lines
979 B
JavaScript
29 lines
979 B
JavaScript
|
|
browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
|
|
if (changeInfo.status !== 'complete') {
|
|
browser.pageAction.hide(tabId);
|
|
await browser.storage.local.remove(`nl_tab_${sender.tab.id}`);
|
|
return;
|
|
}
|
|
}, { properties: ["status"] });
|
|
|
|
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
if (message.action === "showNostrLinksPageAction" && sender.tab?.id) {
|
|
const tabLinks = { [`nl_tab_${sender.tab.id}`]: message.links };
|
|
browser.storage.local.set(tabLinks, () => {
|
|
browser.pageAction.show(sender.tab.id);
|
|
});
|
|
}
|
|
|
|
if (message.action === "getNostrLinks" && message.tabId) {
|
|
browser.storage.local.get(`nl_tab_${message.tabId}`, (result) => {
|
|
sendResponse({ links: result[`nl_tab_${message.tabId}`] || [] });
|
|
});
|
|
return true; // Keep message channel open for async response
|
|
}
|
|
});
|
|
|
|
browser.tabs.onRemoved.addListener((tabId) => {
|
|
browser.storage.local.remove(`nl_tab_${tabId}`);
|
|
});
|