mirror of
https://github.com/aculix/knotchy.git
synced 2026-10-27 07:15:53 +00:00
14 lines
640 B
JavaScript
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 });
|
|
});
|