mirror of
https://github.com/027xiguapi/code-box.git
synced 2026-04-28 15:22:15 +00:00
25 lines
629 B
TypeScript
25 lines
629 B
TypeScript
import { Storage } from "@plasmohq/storage"
|
|
import { useStorage } from "@plasmohq/storage/dist/hook"
|
|
|
|
import Turndown from "~utils/turndown"
|
|
|
|
export function useContent(option?) {
|
|
const turndownService = Turndown(option)
|
|
|
|
const [content, setContent] = useStorage({
|
|
key: "md-content",
|
|
instance: new Storage({
|
|
area: "local"
|
|
})
|
|
})
|
|
|
|
const handleSetContent = (selectors: string) => {
|
|
const html = document.querySelector(selectors)
|
|
const markdown = turndownService.turndown(html)
|
|
setContent(markdown)
|
|
window.open("https://md.randbox.top", "_blank")
|
|
}
|
|
|
|
return [content, handleSetContent]
|
|
}
|