add javlib into siteList

This commit is contained in:
mrbunker
2023-03-11 11:36:00 +08:00
parent 96c6948c6a
commit cb3a6ceb2c
3 changed files with 30 additions and 15 deletions

View File

@@ -1,12 +1,14 @@
import { memo, useState } from "preact/compat";
import { SiteItem, siteList } from "@/utils/siteList";
import { GM_getValue } from "$";
import type { Current } from "@/utils/matchList";
import Setting from "./Setting";
import SiteButton from "./SiteButton";
import { Setting } from "./Setting";
import { GM_getValue } from "$";
import { SiteItem, siteList } from "@/utils/siteList";
import type { Current } from "@/utils/matchList";
const App = memo(function ({ current, CODE }: { current: Current; CODE: string }) {
const disables = GM_getValue<SiteItem["name"][]>("disable", ["AvJoy", "baihuse", "AV01"]);
const defDisables = ["AvJoy", "baihuse", "GGJAV", "AV01", "JavBus", "JavDB", "JAVLib"];
/** 默认不显示的站 */
const disables = GM_getValue<SiteItem["name"][]>("disable", defDisables);
// sites 最原始的 siteList.json
const [sites, setSites] = useState(siteList);

View File

@@ -1,8 +1,8 @@
import { StateUpdater, useRef, useState } from "preact/hooks";
import { SiteItem } from "@/utils/siteList";
import { StateUpdater, useState } from "preact/hooks";
import { GM_setValue } from "vite-plugin-monkey/dist/client";
export const Setting = ({
const Setting = ({
sites,
setSites,
disables: disable,
@@ -13,13 +13,13 @@ export const Setting = ({
}) => {
const [showSetting, setShowSetting] = useState(false);
/** 暂存用户的勾选,最后保存的时候提交 */
const newDisable = disable;
const newDisable = useRef(disable);
return (
<>
{!showSetting ? (
<div
className="jop-button_def"
onClick={(e) => {
onClick={() => {
setShowSetting(!showSetting);
}}
>
@@ -39,14 +39,14 @@ export const Setting = ({
type="checkbox"
className="jop-setting-checkbox"
checked={!disable.includes(item.name)}
onChange={(e: any) => {
const checked: boolean = e.target?.checked;
onChange={(e) => {
const checked = (e.target as HTMLInputElement).checked;
sites[index].disable = !checked;
if (!checked) {
newDisable.push(item.name);
newDisable.current.push(item.name);
} else {
newDisable.forEach((name, index) => {
if (name === item.name) newDisable.splice(index, 1);
newDisable.current = newDisable.current.filter((disableItem) => {
return disableItem !== item.name;
});
}
}}
@@ -59,7 +59,7 @@ export const Setting = ({
className="jop-button_def"
onClick={(e) => {
setShowSetting(!showSetting);
GM_setValue("disable", newDisable);
GM_setValue("disable", newDisable.current);
setSites([...sites]);
}}
>
@@ -70,3 +70,5 @@ export const Setting = ({
</>
);
};
export default Setting;

View File

@@ -254,4 +254,15 @@ export const siteList: SiteItem[] = [
},
method: print,
},
{
name: "JAVLib",
disableHostname: "javlibrary",
disable: false,
hostname: "javlibrary.com",
url: "https://www.javlibrary.com/cn/vl_searchbyid.php?keyword={{code}}",
fetcher: "get",
domQuery: {},
method: print,
},
];