Skip to content

Commit

Permalink
完成编辑markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
027xiguapi committed Oct 10, 2024
1 parent 1bb492b commit aef408f
Show file tree
Hide file tree
Showing 29 changed files with 164 additions and 75 deletions.
25 changes: 25 additions & 0 deletions component/items/editMarkdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { EditOutlined, StarTwoTone } from "@ant-design/icons"

import { sendToContentScript } from "@plasmohq/messaging"

import { i18n } from "~tools"

export default function EditMarkdown(props) {
let { name } = props

async function editMarkdown() {
sendToContentScript({
name: `${name}-editMarkdown`
})
}

return (
<div className="item download" onClick={editMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
{i18n("editMarkdown")}
</span>
<EditOutlined style={{ color: "#52c41a", fontSize: "16px" }} />
</div>
)
}
4 changes: 3 additions & 1 deletion component/options/51cto.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"
import { DownloadOutlined, EditOutlined, StarTwoTone } from "@ant-design/icons"

import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Cto51() {
Expand Down Expand Up @@ -55,6 +56,7 @@ export default function Cto51() {
htmlFor="51cto-closeLoginModal"
className="codebox-switch"></label>
</div>
<EditMarkdown></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
2 changes: 2 additions & 0 deletions component/options/baidu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"
import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Baidu() {
Expand Down Expand Up @@ -37,6 +38,7 @@ export default function Baidu() {
/>
<label className="codebox-switch" htmlFor="baidu-closeAIBox"></label>
</div>
<EditMarkdown name="baidu"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
2 changes: 2 additions & 0 deletions component/options/cnblogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"
import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Cnblogs() {
Expand Down Expand Up @@ -37,6 +38,7 @@ export default function Cnblogs() {
/>
<label className="codebox-switch" htmlFor="cnblogs-copyCode"></label>
</div>
<EditMarkdown name="cnblogs"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
2 changes: 2 additions & 0 deletions component/options/csdn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"
import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Csdn() {
Expand Down Expand Up @@ -135,6 +136,7 @@ export default function Csdn() {
htmlFor="csdn-closeRedirectModal"
className="codebox-switch"></label>
</div>
<EditMarkdown name="csdn"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
15 changes: 2 additions & 13 deletions component/options/custom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useEffect, useState } from "react"
import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Custom() {
Expand All @@ -25,12 +26,6 @@ export default function Custom() {
sendToContentScript({ name: `custom-scrollIntoViewCode`, body: { index } })
}

function editMarkdown() {
sendToContentScript({
name: "custom-editMarkdown"
})
}

function downloadMarkdown() {
sendToContentScript({
name: "custom-downloadMarkdown"
Expand Down Expand Up @@ -92,13 +87,7 @@ export default function Custom() {
onChange={(e) => setRenderValue(e.target.value)}
onBlur={(e) => setStoreValue()}></Input.TextArea>
</div>
<div className="item download" onClick={editMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
{i18n("editMarkdown")}
</span>
<EditOutlined style={{ color: "#52c41a", fontSize: "16px" }} />
</div>
<EditMarkdown name="custom"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
2 changes: 2 additions & 0 deletions component/options/jb51.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"
import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Jb51() {
Expand Down Expand Up @@ -52,6 +53,7 @@ export default function Jb51() {
/>
<label className="codebox-switch" htmlFor="jb51-copyCode"></label>
</div>
<EditMarkdown name="jb51"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
2 changes: 2 additions & 0 deletions component/options/jianshu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"
import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Jianshu() {
Expand Down Expand Up @@ -73,6 +74,7 @@ export default function Jianshu() {
className="codebox-switch"
htmlFor="jianshu-autoOpenCode"></label>
</div>
<EditMarkdown name="jianshu"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
9 changes: 2 additions & 7 deletions component/options/juejin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DownloadOutlined, EditOutlined, StarTwoTone } from "@ant-design/icons"

import { sendToContentScript } from "@plasmohq/messaging"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Juejin() {
Expand All @@ -26,13 +27,7 @@ export default function Juejin() {
return (
<fieldset>
<legend>{i18n("juejinConfig")}</legend>
<div className="item download" onClick={editMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
{i18n("editMarkdown")}
</span>
<EditOutlined style={{ color: "#52c41a", fontSize: "16px" }} />
</div>
<EditMarkdown name="juejin"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
2 changes: 2 additions & 0 deletions component/options/oschina.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"

import { sendToContentScript } from "@plasmohq/messaging"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Oschina() {
Expand All @@ -20,6 +21,7 @@ export default function Oschina() {
return (
<fieldset>
<legend>{i18n("oschinaConfig")}</legend>
<EditMarkdown name="oschina"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
2 changes: 2 additions & 0 deletions component/options/php.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"
import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Php() {
Expand Down Expand Up @@ -53,6 +54,7 @@ export default function Php() {
/>
<label htmlFor="php-closeLoginModal" className="codebox-switch"></label>
</div>
<EditMarkdown name="php"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
2 changes: 2 additions & 0 deletions component/options/segmentfault.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"

import { sendToContentScript } from "@plasmohq/messaging"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Segmentfault() {
Expand All @@ -20,6 +21,7 @@ export default function Segmentfault() {
return (
<fieldset>
<legend>{i18n("segmentfaultConfig")}</legend>
<EditMarkdown name="segmentfault"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
2 changes: 2 additions & 0 deletions component/options/weixin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"
import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/dist/hook"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Weixin() {
Expand Down Expand Up @@ -37,6 +38,7 @@ export default function Weixin() {
/>
<label className="codebox-switch" htmlFor="weixin-copyCode"></label>
</div>
<EditMarkdown name="weixin"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
2 changes: 2 additions & 0 deletions component/options/zhihu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons"
import { sendToContentScript } from "@plasmohq/messaging"
import { useStorage } from "@plasmohq/storage/hook"

import EditMarkdown from "~component/items/editMarkdown"
import { i18n } from "~tools"

export default function Zhihu() {
Expand Down Expand Up @@ -71,6 +72,7 @@ export default function Zhihu() {
/>
<label className="codebox-switch" htmlFor="zhihu-autoOpenCode"></label>
</div>
<EditMarkdown name="zhihu"></EditMarkdown>
<div className="item download" onClick={downloadMarkdown}>
<span>
<StarTwoTone twoToneColor="#eb2f96" style={{ marginRight: "5px" }} />
Expand Down
5 changes: 5 additions & 0 deletions contents/51cto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"

import { addCss, saveHtml, saveMarkdown, setIcon } from "~tools"
import { useContent } from "~utils/editMarkdownHook"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
Expand All @@ -20,6 +21,7 @@ export default function Cto51() {
const [closeLoginModal] = useStorage<boolean>("51cto-closeLoginModal")
const [history, setHistory] = useStorage<any[]>("codebox-history")
const [closeLog] = useStorage("config-closeLog", true)
const [content, setContent] = useContent()

useEffect(() => {
closeLog || console.log("51CTO status", { closeLoginModal, copyCode })
Expand All @@ -34,6 +36,9 @@ export default function Cto51() {
if (req.name == "51cto-isShow") {
res.send({ isShow: true })
}
if (req.name == "51cto-editMarkdown") {
setContent("article")
}
if (req.name == "51cto-downloadMarkdown") {
downloadMarkdown()
}
Expand Down
12 changes: 12 additions & 0 deletions contents/baidu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"

import { addCss, saveHtml, saveMarkdown, setIcon } from "~tools"
import { useContent } from "~utils/editMarkdownHook"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
Expand All @@ -17,6 +18,7 @@ const articleTitle = document.querySelector<HTMLElement>("head title").innerText
export default function Custom() {
const [closeAIBox] = useStorage<boolean>("baidu-closeAIBox")
const [closeLog] = useStorage("config-closeLog", true)
const [content, setContent] = useContent()

useEffect(() => {
closeLog || console.log("baidu", { closeAIBox })
Expand All @@ -28,6 +30,9 @@ export default function Custom() {
if (req.name == "baidu-isShow") {
res.send({ isShow: true })
}
if (req.name == "baidu-editMarkdown") {
setContent(".wd-ai-index-pc")
}
if (req.name == "baidu-downloadMarkdown") {
downloadMarkdown()
}
Expand All @@ -43,6 +48,13 @@ export default function Custom() {
}`)
}

function editMarkdown() {
const html = document.querySelector("article.article")
const markdown = turndownService.turndown(html)
setContent(markdown)
window.open("https://md.randbox.top", "_blank")
}

function downloadMarkdown() {
const html = document.querySelector(".wd-ai-index-pc")
const markdown = turndownService.turndown(html)
Expand Down
5 changes: 5 additions & 0 deletions contents/cnblogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"

import { saveHtml, saveMarkdown, setIcon } from "~tools"
import { useContent } from "~utils/editMarkdownHook"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
Expand All @@ -20,6 +21,7 @@ export default function cnblogs() {
const [copyCode] = useStorage<boolean>("cnblogs-copyCode")
const [history, setHistory] = useStorage<any[]>("codebox-history")
const [closeLog] = useStorage("config-closeLog", true)
const [content, setContent] = useContent()

useEffect(() => {
closeLog || console.log("cnblogs copyCode", copyCode)
Expand All @@ -31,6 +33,9 @@ export default function cnblogs() {
if (req.name == "cnblogs-isShow") {
res.send({ isShow: true })
}
if (req.name == "cnblogs-editMarkdown") {
setContent("article.article")
}
if (req.name == "cnblogs-downloadMarkdown") {
downloadMarkdown()
}
Expand Down
5 changes: 5 additions & 0 deletions contents/csdn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useMessage } from "@plasmohq/messaging/hook"
import { useStorage } from "@plasmohq/storage/hook"

import { addCss, saveHtml, saveMarkdown, setIcon } from "~tools"
import { useContent } from "~utils/editMarkdownHook"
import Turndown from "~utils/turndown"

export const config: PlasmoCSConfig = {
Expand All @@ -25,6 +26,7 @@ const csdn = () => {
const [closeRedirectModal] = useStorage<boolean>("csdn-closeLoginModal")
const [history, setHistory] = useStorage<any[]>("codebox-history")
const [closeLog] = useStorage("config-closeLog", true)
const [content, setContent] = useContent()

useEffect(() => {
closeLog ||
Expand Down Expand Up @@ -65,6 +67,9 @@ const csdn = () => {
if (req.name == "csdn-isShow") {
res.send({ isShow: true })
}
if (req.name == "csdn-editMarkdown") {
setContent(".blog-content-box")
}
if (req.name == "csdn-downloadMarkdown") {
downloadMarkdown()
}
Expand Down
Loading

0 comments on commit aef408f

Please sign in to comment.