mirror of
https://github.com/027xiguapi/code-box.git
synced 2026-09-26 09:08:23 +00:00
增加侧边栏
This commit is contained in:
@@ -24,3 +24,31 @@ chrome.runtime.requestUpdateCheck(function (status, details) {
|
||||
console.log("更新检查被限流。")
|
||||
}
|
||||
})
|
||||
|
||||
chrome.tabs.onUpdated.addListener((tabId, _, tab) => {
|
||||
// console.log(tabId, _, tab)
|
||||
// if (!("sidePanel" in chrome)) {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// void (async () => {
|
||||
// if (!tab.url) {
|
||||
// return
|
||||
// }
|
||||
// // const url = new URL(tab.url)
|
||||
// // if (
|
||||
// // url.origin === ""
|
||||
// // ) {
|
||||
// // await chrome.sidePanel.setOptions({
|
||||
// // tabId,
|
||||
// // // path: "pages/options.html",
|
||||
// // enabled: true
|
||||
// // })
|
||||
// // } else {
|
||||
// // await chrome.sidePanel.setOptions({
|
||||
// // tabId,
|
||||
// // enabled: false
|
||||
// // })
|
||||
// // }
|
||||
// })()
|
||||
})
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { PlasmoMessaging } from "@plasmohq/messaging"
|
||||
|
||||
const handler: PlasmoMessaging.MessageHandler = (req, res) => {
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => {
|
||||
chrome.sidePanel.open({ tabId: tab.id })
|
||||
})
|
||||
}
|
||||
|
||||
export default handler
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { useEffect, useState } from "react"
|
||||
|
||||
import { sendToContentScript } from "@plasmohq/messaging"
|
||||
import { useStorage } from "@plasmohq/storage/dist/hook"
|
||||
|
||||
import Cto51 from "~component/options/51cto"
|
||||
import Baidu from "~component/options/baidu"
|
||||
@@ -18,6 +19,7 @@ import Weixin from "~component/options/weixin"
|
||||
import Zhihu from "~component/options/zhihu"
|
||||
|
||||
export default function Content() {
|
||||
const [closeLog] = useStorage("config-closeLog", true)
|
||||
const [csdnIsShow, setCsdnIsShow] = useState<boolean>(false)
|
||||
const [zhihuIsShow, setZhihuIsShow] = useState<boolean>(false)
|
||||
const [baiduIsShow, setBaiduIsShow] = useState<boolean>(false)
|
||||
@@ -64,9 +66,14 @@ export default function Content() {
|
||||
custom: setCustomIsShow
|
||||
}
|
||||
|
||||
async function getIsShow(type) {
|
||||
const res = await sendToContentScript({ name: `${type}-isShow` })
|
||||
res?.isShow && setIsShowMap[type] && setIsShowMap[type](res.isShow)
|
||||
function getIsShow(type) {
|
||||
sendToContentScript({ name: `${type}-isShow` })
|
||||
.then((res) => {
|
||||
res?.isShow && setIsShowMap[type] && setIsShowMap[type](res.isShow)
|
||||
})
|
||||
.catch((err) => {
|
||||
closeLog || console.log("getIsShow", err)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -11,18 +11,22 @@ export default function Custom() {
|
||||
v === undefined ? false : v
|
||||
)
|
||||
const [cssCode, setCssCode] = useStorage("custom-cssCode")
|
||||
const [closeLog] = useStorage("config-closeLog", true)
|
||||
|
||||
const [codes, setCodes] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
if (window.location.protocol != "chrome-extension:") {
|
||||
getCodes()
|
||||
}
|
||||
getCodes()
|
||||
}, [])
|
||||
|
||||
async function getCodes() {
|
||||
const res = await sendToContentScript({ name: `custom-getCodes` })
|
||||
res?.codes && setCodes(res?.codes)
|
||||
sendToContentScript({ name: `custom-getCodes` })
|
||||
.then((res) => {
|
||||
res?.codes && setCodes(res?.codes)
|
||||
})
|
||||
.catch((err) => {
|
||||
closeLog || console.log("getCodes", err)
|
||||
})
|
||||
}
|
||||
|
||||
function downloadCode(index) {
|
||||
|
||||
+8
-4
@@ -173,9 +173,11 @@ export default function CustomOverlay() {
|
||||
target.classList.add("codebox-current")
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
if (confirm("是否下载?")) {
|
||||
handleDownload()
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (confirm("是否下载?")) {
|
||||
handleDownload()
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -209,7 +211,6 @@ export default function CustomOverlay() {
|
||||
function handleDownload() {
|
||||
const currentDom = document.querySelector(".codebox-current")
|
||||
removeCurrentDom()
|
||||
setIsCurrentDom(false)
|
||||
if (isDownloadType == "html") {
|
||||
downloadHtml(currentDom)
|
||||
} else if (isDownloadType == "markdown") {
|
||||
@@ -219,6 +220,9 @@ export default function CustomOverlay() {
|
||||
} else if (isDownloadType == "img") {
|
||||
downloadImg(currentDom)
|
||||
}
|
||||
isReady = false
|
||||
isSelect = false
|
||||
setIsCurrentDom(false)
|
||||
}
|
||||
|
||||
function handleConfirm() {
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
"history": {
|
||||
"message": "Historical records"
|
||||
},
|
||||
"sidePanel": {
|
||||
"message": "Side Panel"
|
||||
},
|
||||
"more": {
|
||||
"message": "More settings"
|
||||
},
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
"history": {
|
||||
"message": "历史记录"
|
||||
},
|
||||
"sidePanel": {
|
||||
"message": "侧边栏"
|
||||
},
|
||||
"more": {
|
||||
"message": "更多设置"
|
||||
},
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "code-box",
|
||||
"displayName": "__MSG_extensionName__",
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.2",
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"author": "027xiguapi. <458813868@qq.com>",
|
||||
"scripts": {
|
||||
|
||||
@@ -4,7 +4,18 @@ import { i18n } from "~tools"
|
||||
|
||||
import "~index.css"
|
||||
|
||||
import { sendToBackground } from "@plasmohq/messaging"
|
||||
|
||||
export default function IndexPopup() {
|
||||
function hanleOpenSidePanel() {
|
||||
sendToBackground({
|
||||
name: "sidepanel",
|
||||
body: {
|
||||
active: true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<ThemeProvider>
|
||||
<div className="App popup">
|
||||
@@ -16,6 +27,11 @@ export default function IndexPopup() {
|
||||
<Content />
|
||||
</div>
|
||||
<div className="App-link">
|
||||
<div className="item">
|
||||
<a className="btn" href="#" onClick={hanleOpenSidePanel}>
|
||||
{i18n("sidePanel")}😀
|
||||
</a>
|
||||
</div>
|
||||
<div className="item">
|
||||
<a
|
||||
className="btn"
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
.sidepanel {
|
||||
margin: 0 auto;
|
||||
padding: 10px 15px;
|
||||
:global {
|
||||
.wechat {
|
||||
text-align: center;
|
||||
.wechatDesc {
|
||||
font-size: 14px;
|
||||
color: red;
|
||||
}
|
||||
.wechatImg {
|
||||
margin: 0 auto;
|
||||
width: 150px;
|
||||
}
|
||||
}
|
||||
.item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
font-size: 16px;
|
||||
}
|
||||
.item.download {
|
||||
cursor: pointer;
|
||||
}
|
||||
.item.code {
|
||||
cursor: pointer;
|
||||
height: 20px;
|
||||
}
|
||||
.item.code .codeTxt {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
width: auto;
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import { ThemeProvider } from "~theme"
|
||||
|
||||
import "~index.css"
|
||||
|
||||
import {
|
||||
DownloadOutlined,
|
||||
KeyOutlined,
|
||||
PushpinOutlined
|
||||
} from "@ant-design/icons"
|
||||
import { Button, Input, Space } from "antd"
|
||||
import qrcodeUrl from "raw:~/public/wx/qrcode_wx.jpg"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import { sendToContentScript } from "@plasmohq/messaging"
|
||||
import { useStorage } from "@plasmohq/storage/dist/hook"
|
||||
|
||||
import styles from "./index.module.scss"
|
||||
|
||||
function IndexSidePanel() {
|
||||
const [codes, setCodes] = useState([])
|
||||
const [closeLog] = useStorage("config-closeLog", true)
|
||||
|
||||
useEffect(() => {
|
||||
getCodes()
|
||||
}, [])
|
||||
|
||||
async function getCodes() {
|
||||
sendToContentScript({ name: `custom-getCodes` })
|
||||
.then((res) => {
|
||||
res?.codes && setCodes(res?.codes)
|
||||
})
|
||||
.catch((err) => {
|
||||
closeLog || console.log("getCodes", err)
|
||||
})
|
||||
}
|
||||
|
||||
function pinCode(index) {
|
||||
sendToContentScript({ name: `custom-scrollIntoViewCode`, body: { index } })
|
||||
}
|
||||
|
||||
function downloadCode(index) {
|
||||
sendToContentScript({ name: `custom-downloadCode`, body: { index } })
|
||||
}
|
||||
|
||||
function handleSubmit() {}
|
||||
|
||||
return (
|
||||
<ThemeProvider>
|
||||
<div className={`${styles.sidepanel}`}>
|
||||
<div className="wechat">
|
||||
<h1>微信公众号</h1>
|
||||
<p className="wechatDesc">关注公众号,了解更多功能</p>
|
||||
<img className="wechatImg" src={qrcodeUrl} alt="微信公众号" />
|
||||
<Space.Compact style={{ width: "100%" }}>
|
||||
<Input placeholder="输入激活码" prefix={<KeyOutlined />} />
|
||||
<Button type="primary" onClick={handleSubmit}>
|
||||
提交
|
||||
</Button>
|
||||
</Space.Compact>
|
||||
</div>
|
||||
{codes.map((code, index) => (
|
||||
<div className="item code" onClick={() => pinCode(index)} key={index}>
|
||||
<span className="codeTxt">
|
||||
{index + 1}-{JSON.stringify(code)}
|
||||
</span>
|
||||
<PushpinOutlined
|
||||
style={{ color: "#52c41a", fontSize: "16px", marginLeft: "10px" }}
|
||||
className="download"
|
||||
onClick={() => pinCode(index)}
|
||||
/>
|
||||
<DownloadOutlined
|
||||
style={{ color: "#52c41a", fontSize: "16px", marginLeft: "10px" }}
|
||||
className="download"
|
||||
onClick={() => downloadCode(index)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</ThemeProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export default IndexSidePanel
|
||||
Reference in New Issue
Block a user