Files
2026-09-28 18:28:32 +05:30

14 lines
640 B
JavaScript

// Chrome gives the Services menu a link's text, never its address, hence this extension.
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({ id: "open-in-knotchy", title: "Open in Knotchy", contexts: ["link"] });
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId !== "open-in-knotchy" || !info.linkUrl || !tab || tab.id === undefined) return;
if (!/^https?:\/\//i.test(info.linkUrl)) return;
const target = "knotchy://open?url=" + encodeURIComponent(info.linkUrl);
// Hands the URL to the app without leaving the page.
chrome.tabs.update(tab.id, { url: target });
});