优化编辑markdown

This commit is contained in:
fzk
2025-02-08 14:00:31 +08:00
parent 5439443271
commit 4c61ca2cae
17 changed files with 41 additions and 42 deletions

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -235,7 +235,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
function editMarkdown() {
const dom = document.querySelector("#article")
setEditMarkdown(dom)
setEditMarkdown(dom, articleTitle)
}
function downloadMarkdown() {

View File

@@ -185,7 +185,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
function editMarkdown() {
const dom = document.querySelector("section.ouvJEz")
setContent(dom)
setContent(dom, articleTitle)
}
function downloadMarkdown() {

View File

@@ -100,7 +100,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
function editMarkdown() {
const dom = document.querySelector("article.article")
setContent(dom)
setContent(dom, articleTitle)
}
function downloadMarkdown() {

View File

@@ -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>
}

View File

@@ -143,7 +143,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
function editMarkdown() {
const dom = document.querySelector("article")
setContent(dom)
setContent(dom, articleTitle)
}
function downloadMarkdown() {

View File

@@ -71,7 +71,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
function editMarkdown() {
const dom = document.querySelector(".article-box")
setContent(dom)
setContent(dom, articleTitle)
}
function downloadMarkdown() {

View File

@@ -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() {

View File

@@ -74,7 +74,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
function editMarkdown() {
const dom = document.querySelector(".container")
setContent(dom)
setContent(dom, articleTitle)
}
function downloadMarkdown() {

View File

@@ -141,7 +141,7 @@ const PlasmoOverlay: FC<PlasmoCSUIProps> = ({ anchor }) => {
function editMarkdown() {
const dom = document.querySelector("#img-content")
setContent(dom)
setContent(dom, articleTitle)
}
function downloadMarkdown() {

View File

@@ -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() {

View File

@@ -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": {

View File

@@ -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) => {

View File

@@ -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]
}