Skip to content

Commit

Permalink
动态设置icon
Browse files Browse the repository at this point in the history
  • Loading branch information
027xiguapi committed Jul 30, 2024
1 parent 022220f commit 804bffa
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 5 deletions.
Binary file modified assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion background.ts → background/index.ts
Original file line number Diff line number Diff line change
@@ -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") })
}
Expand Down
19 changes: 19 additions & 0 deletions background/messages/icon.ts
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions background/messages/ping.ts
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion component/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function Content() {
return (
<>
{items.map((item, index) => (
item.isShow ? itemMap[item.value] : <></>
item.isShow ? <span key={index}>{itemMap[item.value]}</span> : <></>
))}
</>
)
Expand Down
17 changes: 15 additions & 2 deletions contents/51cto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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(`
Expand All @@ -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))

// 功能一: 修改复制按钮,支持一键复制
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
Binary file added public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 804bffa

Please sign in to comment.