Compare commits

..

2 Commits

Author SHA1 Message Date
奇趣保罗 803b6b8e10 fix component props 2024-09-05 02:20:21 +08:00
奇趣保罗 ef23dda691 Add copy links to markdown
复制链接到 Markdown
2024-09-05 02:19:59 +08:00
6 changed files with 56 additions and 4 deletions

View File

@ -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;

View File

@ -1 +1,5 @@
import initContextMenus from "./bindContextMenus";
initContextMenus();
export {};

View File

@ -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 {

13
contents/copy.ts Normal file
View File

@ -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})`);
}
});

View File

@ -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(" - ")) {

View File

@ -27,7 +27,7 @@
},
"manifest": {
"permissions": [
"tabs", "storage", "scripting"
"tabs", "storage", "scripting", "contextMenus"
],
"host_permissions": [
"https://*/*"