parent
a95d919b0e
commit
ef23dda691
|
|
@ -0,0 +1,35 @@
|
|||
const initContextMenus = async () => {
|
||||
chrome.contextMenus.onClicked.addListener(async (info) => {
|
||||
switch (info.menuItemId) {
|
||||
case "copy_markdown_links":
|
||||
case "copy_markdown_links_full":
|
||||
let tab: chrome.tabs.Tab;
|
||||
|
||||
[tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
|
||||
|
||||
if (tab && !tab.url.includes("chrome")) {
|
||||
const messageType = info.menuItemId === "copy_markdown_links"
|
||||
? "toolbox:copyLinkToMarkdown"
|
||||
: "toolbox:copyLinkToMarkdownFull";
|
||||
|
||||
return await chrome.tabs.sendMessage(tab.id, { type: messageType });
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
chrome.contextMenus.create({
|
||||
title: "复制链接为 Markdown",
|
||||
contexts: ["page"],
|
||||
id: "copy_markdown_links",
|
||||
});
|
||||
|
||||
chrome.contextMenus.create({
|
||||
title: "复制完整链接为 Markdown",
|
||||
contexts: ["page"],
|
||||
id: "copy_markdown_links_full",
|
||||
});
|
||||
};
|
||||
|
||||
export default initContextMenus;
|
||||
|
|
@ -1 +1,5 @@
|
|||
import initContextMenus from "./bindContextMenus";
|
||||
|
||||
initContextMenus();
|
||||
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
chrome.runtime.onMessage.addListener((req) => {
|
||||
// 复制精简链接
|
||||
if (req.type === "toolbox:copyLinkToMarkdown") {
|
||||
const link = `${location.origin}${location.pathname}`;
|
||||
|
||||
navigator.clipboard.writeText(`[${document.title}](${link})`);
|
||||
}
|
||||
|
||||
// 复制完整链接带参数
|
||||
if (req.type === "toolbox:copyLinkToMarkdownFull") {
|
||||
navigator.clipboard.writeText(`[${document.title}](${location.href})`);
|
||||
}
|
||||
});
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
},
|
||||
"manifest": {
|
||||
"permissions": [
|
||||
"tabs", "storage", "scripting"
|
||||
"tabs", "storage", "scripting", "contextMenus"
|
||||
],
|
||||
"host_permissions": [
|
||||
"https://*/*"
|
||||
|
|
|
|||
Loading…
Reference in New Issue