diff --git a/component/items/cssCode.tsx b/component/items/cssCode.tsx index a4301b3..6ea78ac 100644 --- a/component/items/cssCode.tsx +++ b/component/items/cssCode.tsx @@ -7,7 +7,9 @@ import { i18n } from "~tools" export default function CssCode(props) { let { name } = props - const [runCss, setRunCss] = useStorage(`${name}-runCss`, false) + const [runCss, setRunCss] = useStorage(`${name}-runCss`, (v) => + v === undefined ? false : v + ) const [cssCode, setCssCode, { setRenderValue, setStoreValue, remove }] = useStorage(`${name}-cssCode`) diff --git a/component/options/51cto.tsx b/component/options/51cto.tsx index d25b339..c50613f 100644 --- a/component/options/51cto.tsx +++ b/component/options/51cto.tsx @@ -1,3 +1,5 @@ +import { useImperativeHandle } from "react" + import { useStorage } from "@plasmohq/storage/hook" import CssCode from "~component/items/cssCode" @@ -7,7 +9,7 @@ import EditMarkdown from "~component/items/editMarkdown" import ShowTag from "~component/items/showTag" import { i18n } from "~tools" -export default function Cto51() { +export default function Cto51({ forwardRef }) { const [copyCode, setCopyCode] = useStorage("51cto-copyCode", (v) => v === undefined ? true : v ) @@ -16,6 +18,15 @@ export default function Cto51() { (v) => (v === undefined ? true : v) ) + function handleReset() { + setCopyCode(true) + setCloseLoginModal(true) + } + + useImperativeHandle(forwardRef, () => ({ + handleReset + })) + return (
{i18n("51ctoConfig")} @@ -45,11 +56,11 @@ export default function Cto51() { htmlFor="51cto-closeLoginModal" className="codebox-switch"> + -
) } diff --git a/component/options/baidu.tsx b/component/options/baidu.tsx index 1660827..08a5fa1 100644 --- a/component/options/baidu.tsx +++ b/component/options/baidu.tsx @@ -1,15 +1,26 @@ +import { useImperativeHandle } from "react" + import { useStorage } from "@plasmohq/storage/hook" +import CssCode from "~component/items/cssCode" import DownloadHtml from "~component/items/downloadHtml" import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" import { i18n } from "~tools" -export default function Baidu() { +export default function Baidu({ forwardRef }) { const [closeAIBox, setCloseAIBox] = useStorage("baidu-closeAIBox", (v) => v === undefined ? false : v ) + function handleReset() { + setCloseAIBox(false) + } + + useImperativeHandle(forwardRef, () => ({ + handleReset + })) + return (
{i18n("baiduConfig")} @@ -25,6 +36,7 @@ export default function Baidu() { /> + diff --git a/component/options/cnblogs.tsx b/component/options/cnblogs.tsx index 5bd287d..e885535 100644 --- a/component/options/cnblogs.tsx +++ b/component/options/cnblogs.tsx @@ -1,3 +1,5 @@ +import { useImperativeHandle } from "react" + import { useStorage } from "@plasmohq/storage/hook" import CssCode from "~component/items/cssCode" @@ -6,11 +8,19 @@ import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" import { i18n } from "~tools" -export default function Cnblogs() { +export default function Cnblogs({ forwardRef }) { const [copyCode, setCopyCode] = useStorage("cnblogs-copyCode", (v) => v === undefined ? true : v ) + function handleReset() { + setCopyCode(true) + } + + useImperativeHandle(forwardRef, () => ({ + handleReset + })) + return (
{i18n("cnblogsConfig")} @@ -26,6 +36,7 @@ export default function Cnblogs() { /> + diff --git a/component/options/config.tsx b/component/options/config.tsx index 2888c24..17ddccc 100644 --- a/component/options/config.tsx +++ b/component/options/config.tsx @@ -1,11 +1,12 @@ import { DownloadOutlined, StarTwoTone } from "@ant-design/icons" +import { useImperativeHandle } from "react" import { sendToBackground, sendToContentScript } from "@plasmohq/messaging" import { useStorage } from "@plasmohq/storage/hook" import { i18n } from "~tools" -export default function Config() { +export default function Config({ forwardRef }) { const [copyCode, setCopyCode] = useStorage("config-copyCode", (v) => v === undefined ? true : v ) @@ -19,6 +20,15 @@ export default function Config() { }) } + function handleReset() { + setCopyCode(true) + setCloseLog(true) + } + + useImperativeHandle(forwardRef, () => ({ + handleReset + })) + return (
{i18n("AppConfig")} diff --git a/component/options/csdn.tsx b/component/options/csdn.tsx index cc9ed92..575bde9 100644 --- a/component/options/csdn.tsx +++ b/component/options/csdn.tsx @@ -1,12 +1,15 @@ +import { useImperativeHandle } from "react" + import { useStorage } from "@plasmohq/storage/hook" +import CssCode from "~component/items/cssCode" import DownloadHtml from "~component/items/downloadHtml" import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" import ShowTag from "~component/items/showTag" import { i18n } from "~tools" -export default function Csdn() { +export default function Csdn({ forwardRef }) { const [closeAds, setCloseAds] = useStorage("csdn-closeAds", (v) => v === undefined ? true : v ) @@ -33,6 +36,20 @@ export default function Csdn() { (v) => (v === undefined ? true : v) ) + function handleReset() { + setCloseAds(true) + setCopyCode(true) + setCloseFollow(true) + setCloseVip(true) + setAutoOpenCode(true) + setCloseLoginModal(true) + setCloseRedirectModal(true) + } + + useImperativeHandle(forwardRef, () => ({ + handleReset + })) + return (
{i18n("csdnConfig")} @@ -124,6 +141,7 @@ export default function Csdn() { htmlFor="csdn-closeRedirectModal" className="codebox-switch"> + diff --git a/component/options/jb51.tsx b/component/options/jb51.tsx index 7d389e2..8db5b22 100644 --- a/component/options/jb51.tsx +++ b/component/options/jb51.tsx @@ -1,11 +1,14 @@ +import { useImperativeHandle } from "react" + import { useStorage } from "@plasmohq/storage/hook" +import CssCode from "~component/items/cssCode" import DownloadHtml from "~component/items/downloadHtml" import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" import { i18n } from "~tools" -export default function Jb51() { +export default function Jb51({ forwardRef }) { const [closeAds, setCloseAds] = useStorage("jb51-closeAds", (v) => v === undefined ? true : v ) @@ -13,6 +16,15 @@ export default function Jb51() { v === undefined ? true : v ) + function handleReset() { + setCopyCode(true) + setCloseAds(true) + } + + useImperativeHandle(forwardRef, () => ({ + handleReset + })) + return (
{i18n("jb51Config")} @@ -40,6 +52,7 @@ export default function Jb51() { /> + diff --git a/component/options/jianshu.tsx b/component/options/jianshu.tsx index 1645db1..9473751 100644 --- a/component/options/jianshu.tsx +++ b/component/options/jianshu.tsx @@ -1,11 +1,14 @@ +import { useImperativeHandle } from "react" + import { useStorage } from "@plasmohq/storage/hook" +import CssCode from "~component/items/cssCode" import DownloadHtml from "~component/items/downloadHtml" import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" import { i18n } from "~tools" -export default function Jianshu() { +export default function Jianshu({ forwardRef }) { const [copyCode, setCopyCode] = useStorage("jianshu-copyCode", (v) => v === undefined ? true : v ) @@ -18,6 +21,16 @@ export default function Jianshu() { (v) => (v === undefined ? true : v) ) + function handleReset() { + setCopyCode(true) + setCloseLoginModal(true) + setAutoOpenCode(true) + } + + useImperativeHandle(forwardRef, () => ({ + handleReset + })) + return (
{i18n("jianshuConfig")} @@ -61,6 +74,7 @@ export default function Jianshu() { className="codebox-switch" htmlFor="jianshu-autoOpenCode"> + diff --git a/component/options/juejin.tsx b/component/options/juejin.tsx index e0e66e4..9aa6b0f 100644 --- a/component/options/juejin.tsx +++ b/component/options/juejin.tsx @@ -1,3 +1,4 @@ +import CssCode from "~component/items/cssCode" import DownloadHtml from "~component/items/downloadHtml" import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" @@ -8,6 +9,7 @@ export default function Juejin() { return (
{i18n("juejinConfig")} + diff --git a/component/options/medium.tsx b/component/options/medium.tsx index 911c7f4..6f2665b 100644 --- a/component/options/medium.tsx +++ b/component/options/medium.tsx @@ -1,3 +1,4 @@ +import CssCode from "~component/items/cssCode" import DownloadHtml from "~component/items/downloadHtml" import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" @@ -8,6 +9,7 @@ export default function Medium() { return (
{i18n("mediumConfig")} + diff --git a/component/options/oschina.tsx b/component/options/oschina.tsx index e882b51..ad98e54 100644 --- a/component/options/oschina.tsx +++ b/component/options/oschina.tsx @@ -1,3 +1,4 @@ +import CssCode from "~component/items/cssCode" import DownloadHtml from "~component/items/downloadHtml" import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" @@ -7,6 +8,7 @@ export default function Oschina() { return (
{i18n("oschinaConfig")} + diff --git a/component/options/php.tsx b/component/options/php.tsx index e8e7461..a0da3a6 100644 --- a/component/options/php.tsx +++ b/component/options/php.tsx @@ -1,3 +1,5 @@ +import { useImperativeHandle } from "react" + import { useStorage } from "@plasmohq/storage/hook" import CssCode from "~component/items/cssCode" @@ -6,7 +8,7 @@ import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" import { i18n } from "~tools" -export default function Php() { +export default function Php({ forwardRef }) { const [copyCode, setCopyCode] = useStorage("php-copyCode", (v) => v === undefined ? true : v ) @@ -15,6 +17,15 @@ export default function Php() { (v) => (v === undefined ? true : v) ) + function handleReset() { + setCopyCode(true) + setCloseLoginModal(true) + } + + useImperativeHandle(forwardRef, () => ({ + handleReset + })) + return (
{i18n("phpConfig")} @@ -42,6 +53,7 @@ export default function Php() { /> + diff --git a/component/options/segmentfault.tsx b/component/options/segmentfault.tsx index aac21ee..d8b1345 100644 --- a/component/options/segmentfault.tsx +++ b/component/options/segmentfault.tsx @@ -1,3 +1,4 @@ +import CssCode from "~component/items/cssCode" import DownloadHtml from "~component/items/downloadHtml" import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" @@ -7,6 +8,7 @@ export default function Segmentfault() { return (
{i18n("segmentfaultConfig")} + diff --git a/component/options/sortableItem.tsx b/component/options/sortableItem.tsx deleted file mode 100644 index bc4939a..0000000 --- a/component/options/sortableItem.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import React from "react" - -import Cto51 from "~component/options/51cto" -import Baidu from "~component/options/baidu" -import Cnblogs from "~component/options/cnblogs" -import Config from "~component/options/config" -import Csdn from "~component/options/csdn" -import Custom from "~component/options/custom" -import Jb51 from "~component/options/jb51" -import Jianshu from "~component/options/jianshu" -import Juejin from "~component/options/juejin" -import Oschina from "~component/options/oschina" -import Php from "~component/options/php" -import Segmentfault from "~component/options/segmentfault" -import Weixin from "~component/options/weixin" -import Zhihu from "~component/options/zhihu" - -const itemMap = { - csdn: , - zhihu: , - baidu: , - juejin: , - oschina: , - jianshu: , - jb51: , - cnblogs: , - "51cto": , - php: , - segmentfault: , - weixin: , - custom: , - app: -} - -export default function SortableItem(props) { - const { item } = props - - return
{itemMap[item.value]}
-} diff --git a/component/options/weixin.tsx b/component/options/weixin.tsx index ba1bf62..9137c6f 100644 --- a/component/options/weixin.tsx +++ b/component/options/weixin.tsx @@ -1,3 +1,4 @@ +import CssCode from "~component/items/cssCode" import DownloadHtml from "~component/items/downloadHtml" import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" @@ -8,6 +9,7 @@ export default function Weixin() { return (
{i18n("weixinConfig")} + diff --git a/component/options/zhihu.tsx b/component/options/zhihu.tsx index 32f0fc1..65d4c9a 100644 --- a/component/options/zhihu.tsx +++ b/component/options/zhihu.tsx @@ -1,11 +1,14 @@ +import React, { useImperativeHandle } from "react" + import { useStorage } from "@plasmohq/storage/hook" +import CssCode from "~component/items/cssCode" import DownloadHtml from "~component/items/downloadHtml" import DownloadMarkdown from "~component/items/downloadMarkdown" import EditMarkdown from "~component/items/editMarkdown" import { i18n } from "~tools" -export default function Zhihu() { +export default function Zhihu({ forwardRef }) { const [copyCode, setCopyCode] = useStorage("zhihu-copyCode", (v) => v === undefined ? true : v ) @@ -18,6 +21,16 @@ export default function Zhihu() { (v) => (v === undefined ? true : v) ) + function handleReset() { + setCopyCode(true) + setCloseLoginModal(true) + setAutoOpenCode(true) + } + + useImperativeHandle(forwardRef, () => ({ + handleReset + })) + return (
{i18n("zhihuConfig")} @@ -59,6 +72,7 @@ export default function Zhihu() { /> + diff --git a/options/index.tsx b/options/index.tsx index eb61fd1..3ceb363 100644 --- a/options/index.tsx +++ b/options/index.tsx @@ -1,94 +1,57 @@ -import React, { useState } from "react" +import React, { useRef, useState } from "react" -import SortableItem from "~component/options/sortableItem" import { ThemeProvider } from "~theme" import { i18n } from "~tools" import "~index.css" +import Cto51 from "~component/options/51cto" +import Baidu from "~component/options/baidu" +import Cnblogs from "~component/options/cnblogs" +import Config from "~component/options/config" +import Csdn from "~component/options/csdn" +import Custom from "~component/options/custom" +import Jb51 from "~component/options/jb51" +import Jianshu from "~component/options/jianshu" +import Juejin from "~component/options/juejin" +import Medium from "~component/options/medium" +import Oschina from "~component/options/oschina" +import Php from "~component/options/php" +import Segmentfault from "~component/options/segmentfault" +import Weixin from "~component/options/weixin" +import Zhihu from "~component/options/zhihu" + import styles from "./index.module.scss" export default function IndexOptions() { - const items = [ - { - id: "1", - value: "csdn", - label: "csdn", - isShow: true - }, - { - id: "2", - value: "zhihu", - label: "知乎", - isShow: true - }, - { - id: "3", - value: "baidu", - label: "百度", - isShow: true - }, - { - id: "4", - value: "jianshu", - label: "简书", - isShow: true - }, - { - id: "5", - value: "weixin", - label: "微信", - isShow: true - }, - { - id: "6", - value: "jb51", - label: "脚本之家", - isShow: true - }, - { - id: "7", - value: "cnblogs", - label: "博客园", - isShow: true - }, - { - id: "8", - value: "51cto", - label: "51CTO", - isShow: true - }, - { - id: "9", - value: "juejin", - label: "掘金", - isShow: true - }, - { - id: "10", - value: "oschina", - label: "oschina", - isShow: true - }, - { - id: "11", - value: "segmentfault", - label: "思否", - isShow: true - }, - { - id: "12", - value: "custom", - label: "自定义", - isShow: true - }, - { - id: "13", - value: "app", - label: "app", - isShow: true + const csdnRef = useRef() + const zhihuRef = useRef() + const baiduRef = useRef() + const juejinRef = useRef() + const oschinaRef = useRef() + const jianshuRef = useRef() + const jb51Ref = useRef() + const cnblogsRef = useRef() + const cto51Ref = useRef() + const phpRef = useRef() + const segmentfaultRef = useRef() + const weixinRef = useRef() + const customRef = useRef() + const appRef = useRef() + + function handleReset() { + if (confirm("确认重置配置?")) { + csdnRef.current && csdnRef.current.handleReset() + zhihuRef.current && zhihuRef.current.handleReset() + baiduRef.current && baiduRef.current.handleReset() + jianshuRef.current && jianshuRef.current.handleReset() + jb51Ref.current && jb51Ref.current.handleReset() + cnblogsRef.current && cnblogsRef.current.handleReset() + cto51Ref.current && cto51Ref.current.handleReset() + phpRef.current && phpRef.current.handleReset() + appRef.current && appRef.current.handleReset() } - ] + } return ( @@ -98,14 +61,31 @@ export default function IndexOptions() {

{i18n("popupDescription")}

- {items.map((item, index) => ( - - ))} + + + + + + + + + + + + + + +
{i18n("version")}:{chrome.runtime.getManifest().version}
+
+ +