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