mirror of
https://github.com/027xiguapi/code-box.git
synced 2026-09-27 01:28:26 +00:00
增加 deepseek 解析
This commit is contained in:
@@ -39,6 +39,8 @@ export default function ValidateContent(props) {
|
||||
if (Number(validTime) > dayjs().unix()) {
|
||||
props.handleOk()
|
||||
} else if (process.env.PLASMO_PUBLIC_CODEBOX_SECRET3 == activationCode) {
|
||||
let time = dayjs().add(7, "day").unix()
|
||||
setValidTime(String(time))
|
||||
setIsValid(true)
|
||||
props.handleOk()
|
||||
} else {
|
||||
|
||||
@@ -21,6 +21,7 @@ export default function SetAiType(props) {
|
||||
id="custom-aiType"
|
||||
value={aiType}
|
||||
onChange={(e) => setAiType(e.target.value)}>
|
||||
<option value="deepseek">deepseek</option>
|
||||
<option value="chatgpt">chatGPT</option>
|
||||
<option value="kimi">kimi</option>
|
||||
</select>
|
||||
|
||||
@@ -106,7 +106,6 @@ export default function QRCodeModal({ onClose, onConfirm }: QRCodeModalProps) {
|
||||
const [inputCode, setInputCode] = useState<string>("")
|
||||
const [isValid, setIsValid] = useState<boolean | null>(null)
|
||||
|
||||
// 验证输入
|
||||
const handleVerify = () => {
|
||||
const formattedInput = inputCode.replace(/\s/g, "")
|
||||
const secretKey = process.env.PLASMO_PUBLIC_CODEBOX_SECRET4
|
||||
@@ -117,6 +116,9 @@ export default function QRCodeModal({ onClose, onConfirm }: QRCodeModalProps) {
|
||||
) {
|
||||
setIsValid(true)
|
||||
onConfirm()
|
||||
} else if (process.env.PLASMO_PUBLIC_CODEBOX_SECRET3 == formattedInput) {
|
||||
setIsValid(true)
|
||||
onConfirm()
|
||||
} else {
|
||||
setIsValid(false)
|
||||
}
|
||||
|
||||
+22
-14
@@ -1,3 +1,4 @@
|
||||
import dayjs from "dayjs"
|
||||
import type { PlasmoCSConfig } from "plasmo"
|
||||
import React, { useEffect, useState } from "react"
|
||||
|
||||
@@ -11,9 +12,10 @@ export const config: PlasmoCSConfig = {
|
||||
}
|
||||
|
||||
export default function Chatgpt() {
|
||||
const [validTime, setValidTime] = useStorage("ai-validTime", "1737872293")
|
||||
const [isModalOpen, setIsModalOpen] = useState(false)
|
||||
const [content, setContent] = useStorage({
|
||||
key: "chatgpt-content",
|
||||
key: "ai-content",
|
||||
instance: new Storage({
|
||||
area: "local"
|
||||
})
|
||||
@@ -23,18 +25,22 @@ export default function Chatgpt() {
|
||||
let timer = null
|
||||
let index = 0
|
||||
if (content) {
|
||||
timer = setInterval(() => {
|
||||
const editorElement = document.querySelector(
|
||||
"._prosemirror-parent_cy42l_1 p"
|
||||
)
|
||||
index++
|
||||
if (editorElement && index < 30) {
|
||||
setIsModalOpen(true)
|
||||
clearTimeout(timer)
|
||||
} else if (index >= 30) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, 1000)
|
||||
if (Number(validTime) < dayjs().unix()) {
|
||||
timer = setInterval(() => {
|
||||
const editorElement = document.querySelector(
|
||||
"._prosemirror-parent_cy42l_1 p"
|
||||
)
|
||||
index++
|
||||
if (editorElement && index < 30) {
|
||||
setIsModalOpen(true)
|
||||
clearTimeout(timer)
|
||||
} else if (index >= 30) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, 1000)
|
||||
} else {
|
||||
handleSetContent()
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
clearTimeout(timer)
|
||||
@@ -47,6 +53,9 @@ export default function Chatgpt() {
|
||||
}
|
||||
|
||||
function handleConfirmModal() {
|
||||
let time = dayjs().add(1, "day").unix()
|
||||
|
||||
setValidTime(String(time))
|
||||
handleSetContent()
|
||||
setTimeout(() => {
|
||||
setIsModalOpen(false)
|
||||
@@ -67,7 +76,6 @@ export default function Chatgpt() {
|
||||
"button[data-testid=send-button]"
|
||||
) as HTMLElement
|
||||
index++
|
||||
console.log(buttonElement, index)
|
||||
if (buttonElement && index < 30) {
|
||||
buttonElement.click()
|
||||
setContent("")
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import dayjs from "dayjs"
|
||||
import type { PlasmoCSConfig } from "plasmo"
|
||||
import React, { useEffect, useState } from "react"
|
||||
|
||||
import { Storage } from "@plasmohq/storage"
|
||||
import { useStorage } from "@plasmohq/storage/hook"
|
||||
|
||||
import QRCodeModal from "~component/ui/QRCodeModal"
|
||||
|
||||
export const config: PlasmoCSConfig = {
|
||||
matches: ["https://chat.deepseek.com/*"]
|
||||
}
|
||||
|
||||
export default function Deepseek() {
|
||||
const [validTime, setValidTime] = useStorage("ai-validTime", "1737872293")
|
||||
const [isModalOpen, setIsModalOpen] = useState(false)
|
||||
const [content, setContent] = useStorage({
|
||||
key: "ai-content",
|
||||
instance: new Storage({
|
||||
area: "local"
|
||||
})
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
let timer = null
|
||||
let index = 0
|
||||
if (content) {
|
||||
if (Number(validTime) < dayjs().unix()) {
|
||||
timer = setInterval(() => {
|
||||
const editorElement = document.querySelector(
|
||||
"#chat-input"
|
||||
) as HTMLElement
|
||||
index++
|
||||
if (editorElement && index < 30) {
|
||||
setIsModalOpen(true)
|
||||
clearTimeout(timer)
|
||||
} else if (index >= 30) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, 1000)
|
||||
} else {
|
||||
handleSetContent()
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, [content, validTime])
|
||||
|
||||
const handleCancelModal = () => {
|
||||
setContent("")
|
||||
setIsModalOpen(false)
|
||||
}
|
||||
|
||||
function handleConfirmModal() {
|
||||
let time = dayjs().add(1, "day").unix()
|
||||
|
||||
setValidTime(String(time))
|
||||
handleSetContent()
|
||||
setTimeout(() => {
|
||||
setIsModalOpen(false)
|
||||
}, 500)
|
||||
}
|
||||
|
||||
function handleSetContent() {
|
||||
const editorElement = document.querySelector(
|
||||
"#chat-input"
|
||||
) as HTMLInputElement
|
||||
|
||||
const buttonElement = document.querySelector(".f6d670") as HTMLElement
|
||||
|
||||
if (editorElement) {
|
||||
editorElement.value = content
|
||||
editorElement.dispatchEvent(new Event("input", { bubbles: true }))
|
||||
editorElement.dispatchEvent(new Event("change", { bubbles: true }))
|
||||
editorElement.focus()
|
||||
editorElement.setSelectionRange(
|
||||
editorElement.value.length,
|
||||
editorElement.value.length
|
||||
)
|
||||
document.execCommand("InsertText", false, content)
|
||||
|
||||
setContent("")
|
||||
|
||||
setTimeout(() => {
|
||||
buttonElement.click()
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{isModalOpen && (
|
||||
<QRCodeModal
|
||||
onClose={handleCancelModal}
|
||||
onConfirm={handleConfirmModal}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
+23
-14
@@ -1,3 +1,4 @@
|
||||
import dayjs from "dayjs"
|
||||
import type { PlasmoCSConfig } from "plasmo"
|
||||
import React, { useEffect, useState } from "react"
|
||||
|
||||
@@ -11,9 +12,10 @@ export const config: PlasmoCSConfig = {
|
||||
}
|
||||
|
||||
export default function Kimi() {
|
||||
const [validTime, setValidTime] = useStorage("ai-validTime", "1737872293")
|
||||
const [isModalOpen, setIsModalOpen] = useState(false)
|
||||
const [content, setContent] = useStorage({
|
||||
key: "kimi-content",
|
||||
key: "ai-content",
|
||||
instance: new Storage({
|
||||
area: "local"
|
||||
})
|
||||
@@ -23,23 +25,27 @@ export default function Kimi() {
|
||||
let timer = null
|
||||
let index = 0
|
||||
if (content) {
|
||||
timer = setInterval(() => {
|
||||
const editorElement = document.querySelector(
|
||||
"div[data-lexical-editor=true]"
|
||||
)
|
||||
index++
|
||||
if (editorElement && index < 30) {
|
||||
setIsModalOpen(true)
|
||||
clearTimeout(timer)
|
||||
} else if (index >= 30) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, 1000)
|
||||
if (Number(validTime) < dayjs().unix()) {
|
||||
timer = setInterval(() => {
|
||||
const editorElement = document.querySelector(
|
||||
"div[data-lexical-editor=true]"
|
||||
)
|
||||
index++
|
||||
if (editorElement && index < 30) {
|
||||
setIsModalOpen(true)
|
||||
clearTimeout(timer)
|
||||
} else if (index >= 30) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, 1000)
|
||||
} else {
|
||||
handleSetContent()
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, [content])
|
||||
}, [content, validTime])
|
||||
|
||||
const handleCancelModal = () => {
|
||||
setContent("")
|
||||
@@ -47,6 +53,9 @@ export default function Kimi() {
|
||||
}
|
||||
|
||||
function handleConfirmModal() {
|
||||
let time = dayjs().add(1, "day").unix()
|
||||
|
||||
setValidTime(String(time))
|
||||
handleSetContent()
|
||||
setTimeout(() => {
|
||||
setIsModalOpen(false)
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "code-box",
|
||||
"displayName": "__MSG_extensionName__",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"author": "027xiguapi. <458813868@qq.com>",
|
||||
"scripts": {
|
||||
|
||||
+15
-17
@@ -5,17 +5,9 @@ import Turndown from "~utils/turndown"
|
||||
|
||||
export function useParseMarkdown(option?) {
|
||||
const turndownService = Turndown(option)
|
||||
// let aiType = null
|
||||
|
||||
const [kimiContent, setKimiContent] = useStorage({
|
||||
key: "kimi-content",
|
||||
instance: new Storage({
|
||||
area: "local"
|
||||
})
|
||||
})
|
||||
|
||||
const [chatgptContent, setChatgptContent] = useStorage({
|
||||
key: "chatgpt-content",
|
||||
const [aiContent, setAiContent] = useStorage({
|
||||
key: "ai-content",
|
||||
instance: new Storage({
|
||||
area: "local"
|
||||
})
|
||||
@@ -28,15 +20,21 @@ export function useParseMarkdown(option?) {
|
||||
markdown = `${markdown}
|
||||
将上面的文字,翻译成中文并生成markdown`
|
||||
|
||||
setAiContent(markdown)
|
||||
type = type || aiType
|
||||
if (type == "kimi") {
|
||||
setKimiContent(markdown)
|
||||
window.open("https://kimi.moonshot.cn/", "_blank")
|
||||
} else {
|
||||
setChatgptContent(markdown)
|
||||
window.open("https://chatgpt.com", "_blank")
|
||||
|
||||
switch (type) {
|
||||
case "kimi":
|
||||
window.open("https://kimi.moonshot.cn/", "_blank")
|
||||
break
|
||||
case "chatgpt":
|
||||
window.open("https://chatgpt.com", "_blank")
|
||||
break
|
||||
case "deepseek":
|
||||
window.open("https://chat.deepseek.com/", "_blank")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return [aiType == "kimi" ? kimiContent : chatgptContent, handleSetContent]
|
||||
return [aiContent, handleSetContent]
|
||||
}
|
||||
|
||||
@@ -102,18 +102,3 @@ export class TOTP {
|
||||
return currentTOTP === inputCode
|
||||
}
|
||||
}
|
||||
|
||||
// 示例用法
|
||||
const secretKey = "JBSWY3DPEHPK3PXP"
|
||||
const userInputCode = "123456"
|
||||
|
||||
if (TOTP.isValidSecret(secretKey)) {
|
||||
const isValid = TOTP.verifyTOTP(secretKey, userInputCode)
|
||||
if (isValid) {
|
||||
console.log("验证码正确")
|
||||
} else {
|
||||
console.log("验证码错误")
|
||||
}
|
||||
} else {
|
||||
console.log("密钥格式无效")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user