mirror of
https://github.com/027xiguapi/code-box.git
synced 2026-05-08 19:27:49 +00:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { Storage } from "@plasmohq/storage"
|
|
import { useStorage } from "@plasmohq/storage/dist/hook"
|
|
|
|
import Turndown from "~utils/turndown"
|
|
|
|
export function useParseMarkdown(option?) {
|
|
const turndownService = Turndown(option)
|
|
|
|
const [kimiContent, setKimiContent] = useStorage({
|
|
key: "kimi-content",
|
|
instance: new Storage({
|
|
area: "local"
|
|
})
|
|
})
|
|
|
|
const [chatgptContent, setChatgptContent] = useStorage({
|
|
key: "chatgpt-content",
|
|
instance: new Storage({
|
|
area: "local"
|
|
})
|
|
})
|
|
|
|
const [aiType, setAiType] = useStorage("app-aiType")
|
|
|
|
const handleSetContent = (selectorDom) => {
|
|
let markdown = turndownService.turndown(selectorDom)
|
|
markdown = `${markdown}
|
|
将上面的文字,翻译成中文并生成markdown`
|
|
console.log(aiType)
|
|
if (aiType == "kimi") {
|
|
setKimiContent(markdown)
|
|
window.open("https://kimi.moonshot.cn/", "_blank")
|
|
} else {
|
|
setChatgptContent(markdown)
|
|
window.open("https://chatgpt.com", "_blank")
|
|
}
|
|
}
|
|
|
|
return [aiType == "kimi" ? kimiContent : chatgptContent, handleSetContent]
|
|
}
|