From b8732cbf76461b9f331baab7599a482f848abf02 Mon Sep 17 00:00:00 2001
From: fzk <458813868@qq.com>
Date: Sun, 26 Jan 2025 15:16:39 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20deepseek=20=E8=A7=A3?=
=?UTF-8?q?=E6=9E=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
component/contents/validateContent.tsx | 2 +
component/items/setAiType.tsx | 1 +
component/ui/QRCodeModal.tsx | 4 +-
contents/chatgpt.tsx | 36 +++++----
contents/deepseek.tsx | 101 +++++++++++++++++++++++++
contents/kimi.tsx | 37 +++++----
package.json | 2 +-
utils/parseMarkdownHook.ts | 32 ++++----
utils/totp.ts | 15 ----
9 files changed, 168 insertions(+), 62 deletions(-)
create mode 100644 contents/deepseek.tsx
diff --git a/component/contents/validateContent.tsx b/component/contents/validateContent.tsx
index 10eaaf6..0e733c8 100644
--- a/component/contents/validateContent.tsx
+++ b/component/contents/validateContent.tsx
@@ -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 {
diff --git a/component/items/setAiType.tsx b/component/items/setAiType.tsx
index 409c601..7d1abaa 100644
--- a/component/items/setAiType.tsx
+++ b/component/items/setAiType.tsx
@@ -21,6 +21,7 @@ export default function SetAiType(props) {
id="custom-aiType"
value={aiType}
onChange={(e) => setAiType(e.target.value)}>
+
diff --git a/component/ui/QRCodeModal.tsx b/component/ui/QRCodeModal.tsx
index f2682b5..40fe46c 100644
--- a/component/ui/QRCodeModal.tsx
+++ b/component/ui/QRCodeModal.tsx
@@ -106,7 +106,6 @@ export default function QRCodeModal({ onClose, onConfirm }: QRCodeModalProps) {
const [inputCode, setInputCode] = useState("")
const [isValid, setIsValid] = useState(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)
}
diff --git a/contents/chatgpt.tsx b/contents/chatgpt.tsx
index cb65ad9..ba29d78 100644
--- a/contents/chatgpt.tsx
+++ b/contents/chatgpt.tsx
@@ -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("")
diff --git a/contents/deepseek.tsx b/contents/deepseek.tsx
new file mode 100644
index 0000000..4b67759
--- /dev/null
+++ b/contents/deepseek.tsx
@@ -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 && (
+
+ )}
+ >
+ )
+}
diff --git a/contents/kimi.tsx b/contents/kimi.tsx
index 622d06f..9f4bb3d 100644
--- a/contents/kimi.tsx
+++ b/contents/kimi.tsx
@@ -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)
diff --git a/package.json b/package.json
index 48b2a52..ffeb95b 100644
--- a/package.json
+++ b/package.json
@@ -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": {
diff --git a/utils/parseMarkdownHook.ts b/utils/parseMarkdownHook.ts
index 99c953e..06f84cd 100644
--- a/utils/parseMarkdownHook.ts
+++ b/utils/parseMarkdownHook.ts
@@ -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]
}
diff --git a/utils/totp.ts b/utils/totp.ts
index 189fcad..e6d5299 100644
--- a/utils/totp.ts
+++ b/utils/totp.ts
@@ -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("密钥格式无效")
-}