自定义选择bug

This commit is contained in:
fzk
2024-09-14 10:23:18 +08:00
parent 565500e71d
commit b3689edcce
2 changed files with 35 additions and 27 deletions

View File

@@ -1,3 +1,4 @@
import { Modal } from "antd"
import { useEffect, useState } from "react"
import { useMessage } from "@plasmohq/messaging/hook"
@@ -22,8 +23,11 @@ export default function Custom() {
const [codes, setCodes] = useState([])
useEffect(() => {
runCss && runCssFunc()
getSelection("markdown")
}, [])
useEffect(() => {
runCss && runCssFunc()
}, [runCss])
useMessage(async (req, res) => {
@@ -96,6 +100,7 @@ export default function Custom() {
}
function getSelection(type) {
console.log(999, type)
addCss(`.codebox-current { border: 1px solid #7983ff; }`)
document.addEventListener("mousemove", function (event) {
const target = event.target as HTMLElement
@@ -104,15 +109,30 @@ export default function Custom() {
isSelect && target.classList.add("codebox-current")
})
document.addEventListener("click", function (event) {
if (isDownloadType == "html") {
isSelect && downloadHtml()
} else if (isDownloadType == "markdown") {
isSelect && downloadMarkdown()
} else if (isDownloadType == "pdf") {
isSelect && downloadPdf()
} else if (isDownloadType == "img") {
isSelect && downloadImg()
}
console.log(8888, isDownloadType)
if (!isSelect) return
const currentDom = document.querySelector(".codebox-current")
removeCurrentDom()
isSelect = false
Modal.error({
title: "提示",
content:
"此功能限时免费免登录预计10月份以后需要注册后续可能收费...",
afterClose: () => {
if (isDownloadType == "html") {
downloadHtml(currentDom)
} else if (isDownloadType == "markdown") {
downloadMarkdown(currentDom)
} else if (isDownloadType == "pdf") {
downloadPdf(currentDom)
} else if (isDownloadType == "img") {
downloadImg(currentDom)
}
}
})
event.stopPropagation()
event.preventDefault()
})
}
@@ -123,35 +143,23 @@ export default function Custom() {
})
}
function downloadHtml() {
const currentDom = document.querySelector(".codebox-current")
removeCurrentDom()
function downloadHtml(currentDom) {
saveHtml(currentDom, articleTitle)
isSelect = false
}
function downloadMarkdown() {
const currentDom = document.querySelector(".codebox-current")
removeCurrentDom()
function downloadMarkdown(currentDom) {
const markdown = turndownService.turndown(currentDom)
saveMarkdown(markdown, articleTitle)
isSelect = false
}
function downloadPdf() {
const currentDom = document.querySelector(".codebox-current")
removeCurrentDom()
function downloadPdf(currentDom) {
const pdf = new Dom2Pdf(currentDom, articleTitle)
pdf.downloadPdf()
isSelect = false
}
function downloadImg() {
const currentDom = document.querySelector(".codebox-current")
removeCurrentDom()
function downloadImg(currentDom) {
const img = new Dom2Pdf(currentDom, articleTitle)
img.downloadImg()
isSelect = false
}
return <div style={{ display: "none" }}></div>

View File

@@ -1,7 +1,7 @@
{
"name": "code-box",
"displayName": "__MSG_extensionName__",
"version": "0.6.8",
"version": "0.6.9",
"description": "__MSG_extensionDescription__",
"author": "027xiguapi. <458813868@qq.com>",
"scripts": {