Adapt extension for Chrome support
This commit is contained in:
parent
bb56e269c4
commit
a1a9a01e2c
@ -1,27 +1,27 @@
|
||||
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||
if (changeInfo.status !== 'complete') {
|
||||
browser.pageAction.hide(tabId);
|
||||
browser.storage.local.remove(`nl_tab_${sender.tab.id}`);
|
||||
chrome.action.disable(tabId);
|
||||
chrome.storage.local.remove(`nl_tab_${tabId}`);
|
||||
return;
|
||||
}
|
||||
}, { properties: ["status"] });
|
||||
});
|
||||
|
||||
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
if (message.action === "showNostrLinksPageAction" && sender.tab?.id) {
|
||||
chrome.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);
|
||||
chrome.storage.local.set(tabLinks, () => {
|
||||
chrome.action.enable(sender.tab.id);
|
||||
});
|
||||
}
|
||||
|
||||
if (message.action === "getNostrLinks" && message.tabId) {
|
||||
browser.storage.local.get(`nl_tab_${message.tabId}`, (result) => {
|
||||
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
|
||||
}
|
||||
});
|
||||
|
||||
browser.tabs.onRemoved.addListener((tabId) => {
|
||||
browser.storage.local.remove(`nl_tab_${tabId}`);
|
||||
chrome.tabs.onRemoved.addListener((tabId) => {
|
||||
chrome.storage.local.remove(`nl_tab_${tabId}`);
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
});
|
||||
});
|
||||
|
||||
browser.runtime.sendMessage({
|
||||
chrome.runtime.sendMessage({
|
||||
action: "showNostrLinksPageAction",
|
||||
links: Array.from(linkMap.values())
|
||||
});
|
||||
|
@ -15,9 +15,7 @@
|
||||
"activeTab"
|
||||
],
|
||||
"background": {
|
||||
"scripts": [
|
||||
"background.js"
|
||||
]
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
@ -26,7 +24,7 @@
|
||||
"run_at": "document_start"
|
||||
}
|
||||
],
|
||||
"page_action": {
|
||||
"action": {
|
||||
"default_icon": "icons/nostr.svg",
|
||||
"default_title": "Nostr",
|
||||
"default_popup": "popup/nostr-links.html"
|
||||
|
@ -1,7 +1,7 @@
|
||||
browser.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||
const tabId = tabs[0].id;
|
||||
|
||||
browser.runtime.sendMessage({ action: "getNostrLinks", tabId }, (response) => {
|
||||
chrome.runtime.sendMessage({ action: "getNostrLinks", tabId }, (response) => {
|
||||
const menu = document.getElementById("link-menu");
|
||||
if (response.links && response.links.length > 0) {
|
||||
menu.innerHTML = response.links
|
||||
|
Loading…
x
Reference in New Issue
Block a user