diff --git a/assets/icon.png b/assets/icon.png index b7779e2..bba5087 100644 Binary files a/assets/icon.png and b/assets/icon.png differ diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 0000000..343e349 Binary files /dev/null and b/assets/logo.png differ diff --git a/background.ts b/background/index.ts similarity index 61% rename from background.ts rename to background/index.ts index cc87520..f434bfe 100644 --- a/background.ts +++ b/background/index.ts @@ -1,6 +1,8 @@ export {} -chrome.runtime.onInstalled.addListener(function (object) { +import "@plasmohq/messaging/background" + +chrome.runtime.onInstalled.addListener(function(object) { if (object.reason === chrome.runtime.OnInstalledReason.INSTALL) { chrome.tabs.create({ url: chrome.runtime.getURL("options.html") }) } diff --git a/background/messages/icon.ts b/background/messages/icon.ts new file mode 100644 index 0000000..8edea75 --- /dev/null +++ b/background/messages/icon.ts @@ -0,0 +1,19 @@ +import type { PlasmoMessaging } from "@plasmohq/messaging" +import activeUrl from "raw:~/assets/logo.png" +import defaultUrl from "raw:~/assets/icon.png" + +const handler: PlasmoMessaging.MessageHandler = async (req, res) => { + const { active } = req.body + + if (active) { + chrome.action.setIcon({ path: activeUrl }, () => { + console.log("set icon activeUrl") + }) + } else { + chrome.action.setIcon({ path: defaultUrl }, () => { + console.log("set icon defaultUrl") + }) + } +} + +export default handler \ No newline at end of file diff --git a/background/messages/ping.ts b/background/messages/ping.ts new file mode 100644 index 0000000..08885ed --- /dev/null +++ b/background/messages/ping.ts @@ -0,0 +1,11 @@ +import type { PlasmoMessaging } from "@plasmohq/messaging" + +const handler: PlasmoMessaging.MessageHandler = async (req, res) => { + // const message = await querySomeApi(req.body.id) + // + // res.send({ + // message + // }) +} + +export default handler \ No newline at end of file diff --git a/component/content.tsx b/component/content.tsx index df0378d..898da26 100644 --- a/component/content.tsx +++ b/component/content.tsx @@ -68,7 +68,7 @@ export default function Content() { return ( <> {items.map((item, index) => ( - item.isShow ? itemMap[item.value] : <> + item.isShow ? {itemMap[item.value]} : <> ))} ) diff --git a/contents/51cto.tsx b/contents/51cto.tsx index f88755f..48f8327 100644 --- a/contents/51cto.tsx +++ b/contents/51cto.tsx @@ -2,6 +2,7 @@ import type { PlasmoCSConfig } from "plasmo" import { useEffect } from "react" import { useStorage } from "@plasmohq/storage/hook" +import { sendToBackground } from "@plasmohq/messaging" import { addCss } from "~tools" @@ -20,12 +21,24 @@ export default function Cto51() { useEffect(() => { console.log("51CTO status", { closeLoginModal, copyCode }) - setTimeout(()=>{ + setTimeout(() => { copyCode && copyCodeFunc() }, 500) closeLoginModal && closeLoginModalFunc() + if (copyCode || closeLoginModal) { + setIconFunc() + } }, [copyCode, closeLoginModal]) + function setIconFunc() { + sendToBackground({ + name: "icon", + body: { + active: true + } + }) + } + /* 未登录复制代码 */ function copyCodeCssFunc() { addCss(` @@ -43,7 +56,7 @@ export default function Cto51() { function copyCodeFunc() { copyCodeCssFunc() // 内容区开启复制 - var content_views = document.querySelector("article") + const content_views = document.querySelector("article") content_views && content_views.replaceWith(content_views.cloneNode(true)) // 功能一: 修改复制按钮,支持一键复制 diff --git a/package.json b/package.json index bdf7083..bc8ed22 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "code-box", "displayName": "codebox-免登录一键复制代码(CSDN/知乎/脚本之家/博客园/51CTO博客)", - "version": "0.2.5", + "version": "0.2.6", "description": "本浏览器插件可以用于CSDN/知乎/脚本之家/博客园/51CTO博客/php中文等网站,实现无需登录一键复制代码;支持选中代码;或者代码右上角按钮的一键复制;解除关注博主即可阅读全文提示;去除登录弹窗;去除跳转APP弹窗;页面自定义样式.", "author": "027xiguapi. <458813868@qq.com>", "scripts": { @@ -16,6 +16,7 @@ "@dnd-kit/core": "^6.1.0", "@dnd-kit/sortable": "^8.0.0", "@dnd-kit/utilities": "^3.2.2", + "@plasmohq/messaging": "^0.6.2", "@plasmohq/storage": "^1.11.0", "plasmo": "0.88.0", "react": "18.2.0", diff --git a/public/icon.png b/public/icon.png new file mode 100644 index 0000000..b7779e2 Binary files /dev/null and b/public/icon.png differ