mirror of
https://github.com/027xiguapi/code-box.git
synced 2026-04-28 15:22:15 +00:00
优化编辑markdown
This commit is contained in:
@@ -242,7 +242,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector<HTMLElement>("article .article-detail")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function parseMarkdown() {
|
||||
|
||||
@@ -51,7 +51,7 @@ export default function Custom() {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector(".wd-ai-index-pc")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -155,7 +155,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector<HTMLElement>("#post_detail")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -280,7 +280,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector(".blog-content-box")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -235,7 +235,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector("#article")
|
||||
setEditMarkdown(dom)
|
||||
setEditMarkdown(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -185,7 +185,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector("section.ouvJEz")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -100,7 +100,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector("article.article")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -5,36 +5,32 @@ import { Storage } from "@plasmohq/storage"
|
||||
import { useStorage } from "@plasmohq/storage/dist/hook"
|
||||
|
||||
export const config: PlasmoCSConfig = {
|
||||
matches: ["https://md.randbox.top/*"]
|
||||
matches: ["https://md.randbox.top/*", "https://md.code-box.fun/*"]
|
||||
}
|
||||
|
||||
export default function Markdown() {
|
||||
const [content] = useStorage({
|
||||
key: "md-content",
|
||||
const [post] = useStorage({
|
||||
key: "md-post",
|
||||
instance: new Storage({
|
||||
area: "local"
|
||||
})
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
let timer = null
|
||||
let index = 0
|
||||
if (content) {
|
||||
timer = setInterval(() => {
|
||||
const setValue = (window as any).setValue
|
||||
index++
|
||||
if (setValue && index < 30) {
|
||||
setValue(content)
|
||||
clearTimeout(timer)
|
||||
} else if (index >= 30) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, 1000)
|
||||
if (post) {
|
||||
const posts = JSON.parse(window.localStorage.getItem("MD__posts")) || []
|
||||
const _post = JSON.parse(post)
|
||||
|
||||
if (posts[0] && _post.content != posts[0].content) {
|
||||
posts.unshift({
|
||||
content: _post.content,
|
||||
title: _post.title || "文章1"
|
||||
})
|
||||
window.localStorage.setItem("MD__posts", JSON.stringify(posts))
|
||||
location.reload()
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, [content])
|
||||
}, [post])
|
||||
|
||||
return <div style={{ display: "none" }}></div>
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector("article")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -71,7 +71,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector(".article-box")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -122,7 +122,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector(".phpscMain .php-article")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -74,7 +74,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector(".container")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -141,7 +141,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector("#img-content")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -205,7 +205,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
|
||||
|
||||
function editMarkdown() {
|
||||
const dom = document.querySelector("article.Post-Main")
|
||||
setContent(dom)
|
||||
setContent(dom, articleTitle)
|
||||
}
|
||||
|
||||
function downloadMarkdown() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "code-box",
|
||||
"displayName": "__MSG_extensionName__",
|
||||
"version": "1.0.10",
|
||||
"version": "1.0.11",
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"author": "027xiguapi. <458813868@qq.com>",
|
||||
"scripts": {
|
||||
|
||||
@@ -11,7 +11,6 @@ export async function downloadAllImagesAsZip(filename?: string) {
|
||||
images.forEach((img, index) => {
|
||||
fetchPromises.push(
|
||||
new Promise((resolve) => {
|
||||
console.log(img.src)
|
||||
fetch(img.src)
|
||||
.then((response) => response.blob())
|
||||
.then((blob) => {
|
||||
|
||||
@@ -6,18 +6,22 @@ import Turndown from "~utils/turndown"
|
||||
export function useEditMarkdown(option?) {
|
||||
const turndownService = Turndown(option)
|
||||
|
||||
const [content, setContent] = useStorage({
|
||||
key: "md-content",
|
||||
const [post, setPost] = useStorage({
|
||||
key: "md-post",
|
||||
instance: new Storage({
|
||||
area: "local"
|
||||
})
|
||||
})
|
||||
|
||||
const handleSetContent = (selectorDom) => {
|
||||
const markdown = turndownService.turndown(selectorDom)
|
||||
setContent(markdown)
|
||||
window.open("https://md.randbox.top", "_blank")
|
||||
const handleSetPost = (selectorDom, articleTitle) => {
|
||||
const content = turndownService.turndown(selectorDom)
|
||||
const post = {
|
||||
content: content,
|
||||
title: articleTitle
|
||||
}
|
||||
setPost(JSON.stringify(post))
|
||||
window.open("https://md.code-box.fun", "_blank")
|
||||
}
|
||||
|
||||
return [content, handleSetContent]
|
||||
return [post, handleSetPost]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user