diff --git a/locales/en/messages.json b/locales/en/messages.json index 77ea9429..e9883963 100644 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -160,5 +160,8 @@ }, "paginationNext": { "message": "Next" + }, + "previousInstances": { + "message": "Previous instances" } } diff --git a/locales/zh_CN/messages.json b/locales/zh_CN/messages.json index c4f1e4e1..00da08f6 100644 --- a/locales/zh_CN/messages.json +++ b/locales/zh_CN/messages.json @@ -160,5 +160,8 @@ }, "paginationNext": { "message": "下一页" + }, + "previousInstances": { + "message": "使用过的实例" } } diff --git a/src/options/routes/General.tsx b/src/options/routes/General.tsx index 89e88b10..b2e77935 100644 --- a/src/options/routes/General.tsx +++ b/src/options/routes/General.tsx @@ -1,5 +1,5 @@ import _ from "lodash" -import { Loader2 } from "lucide-react" +import { Loader2, X } from "lucide-react" import { useEffect, useState } from "react" import toast from "react-hot-toast" @@ -13,16 +13,21 @@ import { Label } from "~/lib/components/Label" import { Switch } from "~/lib/components/Switch" import { defaultConfig, setConfig } from "~/lib/config" import { quickSubscriptions } from "~/lib/quick-subscriptions" +import { logoMap } from "~/lib/quick-subscriptions-logos" import report from "~/lib/report" import { getRulesCount, parseRules } from "~/lib/rules" import type { Rules as IRules } from "~/lib/types" import { getRadarRulesUrl } from "~/lib/utils" -import { logoMap } from "~/lib/quick-subscriptions-logos" function General() { let [config] = useStorage("config") config = _.merge({}, defaultConfig, config) const [rules, setRules] = useState({}) + const [rsshubInstanceHistory, setRsshubInstanceHistory] = useStorage( + "rsshubHistory", + [defaultConfig.rsshubDomain], + ) + const [showHistory, setShowHistory] = useState(false) useEffect(() => { sendToBackground({ name: "requestDisplayedRules", @@ -53,6 +58,19 @@ function General() { ) }, []) + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (showHistory && !(event.target as Element).closest(".relative")) { + setShowHistory(false) + } + } + + document.addEventListener("mousedown", handleClickOutside) + return () => { + document.removeEventListener("mousedown", handleClickOutside) + } + }, [showHistory]) + return (

@@ -136,15 +154,51 @@ function General() { - - setConfig({ - rsshubDomain: e.target.value, - }) - } - /> +
+ + setConfig({ + rsshubDomain: e.target.value, + }) + } + onFocus={() => setShowHistory(true)} + /> + + {showHistory && ( +
+ {rsshubInstanceHistory.map((domain) => ( +
+ + +
+ ))} +
+ )} +

@@ -233,6 +293,12 @@ function General() { disabled={rulesUpdating} onClick={() => { setRulesUpdating(true) + if (!rsshubInstanceHistory.includes(config.rsshubDomain)) { + setRsshubInstanceHistory([ + ...rsshubInstanceHistory, + config.rsshubDomain, + ]) + } sendToBackground({ name: "refreshRules", }).then((res) => { @@ -271,7 +337,10 @@ function General() { } as any) } /> -