Compare commits
2 Commits
a95d919b0e
...
803b6b8e10
| Author | SHA1 | Date |
|---|---|---|
|
|
803b6b8e10 | |
|
|
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 {};
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import type { ReactNode, PropsWithChildren } from "react";
|
|||
import styles from "./tab.module.less";
|
||||
|
||||
interface TabProps extends PropsWithChildren {
|
||||
className: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
interface HeaderProps {
|
||||
|
|
|
|||
|
|
@ -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})`);
|
||||
}
|
||||
});
|
||||
|
|
@ -6,11 +6,11 @@ const getTitle = () => {
|
|||
const metaOgTitle = document.querySelector<HTMLMetaElement>(`meta[name="og:title"]`);
|
||||
|
||||
if (metaOgTitle) {
|
||||
return metaOgTitle.getAttribute("content");;
|
||||
return metaOgTitle.getAttribute("content");
|
||||
}
|
||||
|
||||
if (metaTitle) {
|
||||
return metaTitle.getAttribute("content");;
|
||||
return metaTitle.getAttribute("content");
|
||||
}
|
||||
|
||||
if (title.includes(" - ")) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
},
|
||||
"manifest": {
|
||||
"permissions": [
|
||||
"tabs", "storage", "scripting"
|
||||
"tabs", "storage", "scripting", "contextMenus"
|
||||
],
|
||||
"host_permissions": [
|
||||
"https://*/*"
|
||||
|
|
|
|||
Loading…
Reference in New Issue