增加oschina功能模块

This commit is contained in:
fzk
2024-09-02 11:09:36 +08:00
parent df43d05a60
commit ce7ec2c0bd
10 changed files with 108 additions and 21 deletions

View File

@@ -6,7 +6,7 @@ https://github.com/027xiguapi/code-box
## 介绍
本浏览器插件可以用于CSDN/知乎/脚本之家/博客园/博客园/51CTO博客/php中文网等网站,一键下载文章html或markdown文件;实现无需登录一键复制代码;支持选中代码;或者代码右上角按钮的一键复制;解除关注博主即可阅读全文提示;去除登录弹窗;去除跳转APP弹窗.
本浏览器插件可以用于CSDN/知乎/脚本之家/博客园/博客园/51CTO博客/php中文网/掘金等网站,一键下载文章html或markdown文件;实现无需登录一键复制代码;支持选中代码;或者代码右上角按钮的一键复制;解除关注博主即可阅读全文提示;去除登录弹窗;去除跳转APP弹窗.
## 安装

View File

@@ -11,6 +11,7 @@ import Custom from "~component/custom"
import Jb51 from "~component/jb51"
import Jianshu from "~component/jianshu"
import Juejin from "~component/juejin"
import Oschina from "~component/oschina"
import Php from "~component/php"
import Zhihu from "~component/zhihu"
@@ -24,6 +25,7 @@ export default function Content() {
const [ctoIsShow, set51ctoIsShow] = useState<boolean>(false)
const [juejinIsShow, setJuejinIsShow] = useState<boolean>(false)
const [phpIsShow, setPhpIsShow] = useState<boolean>(false)
const [oschinaIsShow, setOschinaIsShow] = useState<boolean>(false)
const [customIsShow, setCustomIsShow] = useState<boolean>(false)
useEffect(() => {
@@ -36,6 +38,7 @@ export default function Content() {
getIsShow("51cto")
getIsShow("juejin")
getIsShow("php")
getIsShow("oschina")
getIsShow("custom")
}, [])
@@ -49,6 +52,7 @@ export default function Content() {
"51cto": set51ctoIsShow,
php: setPhpIsShow,
juejin: setJuejinIsShow,
oschina: setOschinaIsShow,
custom: setCustomIsShow
}
@@ -68,6 +72,7 @@ export default function Content() {
{ctoIsShow ? <Cto51 /> : <></>}
{juejinIsShow ? <Juejin /> : <></>}
{phpIsShow ? <Php /> : <></>}
{oschinaIsShow ? <Oschina /> : <></>}
{customIsShow ? <Custom /> : <></>}
<Config />
</div>

33
component/oschina.tsx Normal file
View File

@@ -0,0 +1,33 @@
import { DownloadOutlined } from "@ant-design/icons"
import { sendToContentScript } from "@plasmohq/messaging"
import { i18n } from "~tools"
export default function Oschina() {
function downloadMarkdown() {
sendToContentScript({
name: "oschina-downloadMarkdown"
})
}
function downloadHtml() {
sendToContentScript({
name: "oschina-downloadHtml"
})
}
return (
<fieldset>
<legend>{i18n("oschinaConfig")}</legend>
<div className="item download" onClick={downloadMarkdown}>
{i18n("downloadMarkdown")}
<DownloadOutlined style={{ color: "#52c41a", fontSize: "16px" }} />
</div>
<div className="item download" onClick={downloadHtml}>
{i18n("downloadHtml")}
<DownloadOutlined style={{ color: "#52c41a", fontSize: "16px" }} />
</div>
</fieldset>
)
}

View File

@@ -10,6 +10,8 @@ import Csdn from "~component/csdn"
import Custom from "~component/custom"
import Jb51 from "~component/jb51"
import Jianshu from "~component/jianshu"
import Juejin from "~component/juejin"
import Oschina from "~component/oschina"
import Php from "~component/php"
import Zhihu from "~component/zhihu"
@@ -19,6 +21,8 @@ const itemMap = {
csdn: <Csdn />,
zhihu: <Zhihu />,
baidu: <Baidu />,
juejin: <Juejin />,
oschina: <Oschina />,
jianshu: <Jianshu />,
jb51: <Jb51 />,
cnblogs: <Cnblogs />,

View File

@@ -24,7 +24,7 @@ const author = article.byline ?? ""
const authorLink = getMetaContentByProperty("article:author")
const domain = window.location.hostname
export default function Custom() {
export default function Juejin() {
useEffect(() => {
setIcon(true)
}, [])

View File

@@ -1,28 +1,55 @@
import type { PlasmoCSConfig } from "plasmo"
import { useEffect } from "react"
import { useStorage } from "@plasmohq/storage/hook"
import { useMessage } from "@plasmohq/messaging/hook"
import { addCss } from "~tools"
import { Readability } from "~node_modules/@mozilla/readability"
import {
getMetaContentByProperty,
saveHtml,
saveMarkdown,
setIcon
} from "~tools"
import Turndown from "~utils/turndown"
export const config: PlasmoCSConfig = {
matches: ["https://*.baidu.com/*"]
matches: ["https://*.oschina.net/*"]
}
export default function Custom() {
const [closeAIBox] = useStorage<boolean>("baidu-closeAIBox")
const [closeLog] = useStorage("config-closeLog", true)
const turndownService = Turndown()
const documentClone = document.cloneNode(true)
const article = new Readability(documentClone as Document, {}).parse()
const articleUrl = window.location.href
const author = article.byline ?? ""
const authorLink = getMetaContentByProperty("article:author")
const domain = window.location.hostname
export default function Oschina() {
useEffect(() => {
closeLog || console.log("baidu", { closeAIBox })
closeAIBox && closeAIBoxFunc()
}, [closeAIBox])
setIcon(true)
}, [])
/* 删除百度AI对话框 */
function closeAIBoxFunc() {
addCss(`.wd-ai-index-pc{
display:none !important;
}`)
useMessage(async (req, res) => {
if (req.name == "oschina-isShow") {
res.send({ isShow: true })
}
if (req.name == "oschina-downloadMarkdown") {
downloadMarkdown()
}
if (req.name == "oschina-downloadHtml") {
downloadHtml()
}
})
function downloadMarkdown() {
const html = document.querySelector(".article-box")
const markdown = turndownService.turndown(html)
saveMarkdown(markdown, article.title)
}
function downloadHtml() {
const dom = document.querySelector(".article-box")
saveHtml(dom, article.title)
}
return <div style={{ display: "none" }}></div>

View File

@@ -133,5 +133,8 @@
},
"juejinConfig": {
"message": "Juejin Config"
},
"oschinaConfig": {
"message": "Oschina Config"
}
}

View File

@@ -1,9 +1,9 @@
{
"extensionName": {
"message": "codebox-免登录一键复制代码"
"message": "codebox-一键复制代码/下载文章"
},
"extensionDescription": {
"message": "实现无需登录一键复制代码;支持选中代码;或者代码右上角按钮的一键复制;解除关注博主即可阅读全文提示;去除登录弹窗;去除跳转APP弹窗;页面自定义样式."
"message": "实现一键下载文章成html或markdown文件;实现无需登录一键复制代码;支持选中代码;或者代码右上角按钮的一键复制;解除关注博主即可阅读全文提示;去除登录弹窗;去除跳转APP弹窗;页面自定义样式."
},
"popupDescription": {
"message": "免登录一键复制代码"
@@ -133,5 +133,8 @@
},
"juejinConfig": {
"message": "掘金设置"
},
"oschinaConfig": {
"message": "oschina设置"
}
}

View File

@@ -68,12 +68,24 @@ export default function IndexOptions() {
},
{
id: "8",
value: "juejin",
label: "掘金",
isShow: true
},
{
id: "9",
value: "oschina",
label: "oschina",
isShow: true
},
{
id: "10",
value: "custom",
label: "自定义",
isShow: true
},
{
id: "9",
id: "11",
value: "app",
label: "app",
isShow: true

View File

@@ -1,7 +1,7 @@
{
"name": "code-box",
"displayName": "__MSG_extensionName__",
"version": "0.5.7",
"version": "0.5.8",
"description": "__MSG_extensionDescription__",
"author": "027xiguapi. <458813868@qq.com>",
"scripts": {
@@ -34,7 +34,7 @@
"dayjs": "^1.11.12",
"file-saver": "^2.0.5",
"jssha": "^3.3.1",
"plasmo": "0.88.0",
"plasmo": "0.89.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"turndown": "^7.2.0",