From e0c6c0e02a1dea076541d9ae878fdc390cbcab74 Mon Sep 17 00:00:00 2001 From: mrbunker Date: Sat, 6 Jan 2024 00:25:10 +0800 Subject: [PATCH] feat: recognize code start with 300 --- src/utils/index.ts | 16 +++++++++------- src/utils/siteList.ts | 4 ++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index 2ee1208..b679555 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,20 +1,21 @@ import { GM_xmlhttpRequest } from "$"; import { type LibItem } from "./libSites"; +import { SP_PREFIX } from "./siteList"; -const isCaseInsensitiveEqual = (str1: string, str2: string) => { +export const isCaseInsensitiveEqual = (str1: string, str2: string) => { return str1.toLowerCase() === str2.toLowerCase(); }; -const isErrorCode = (resCode: number) => { +export const isErrorCode = (resCode: number) => { return [404, 403].includes(resCode); }; -const regEnum = { +export const regEnum = { subtitle: /(中文|字幕|subtitle)/, leakage: /(无码|無碼|泄漏|Uncensored)/, }; -const getCode = (libItem: LibItem): string => { +export const getCode = (libItem: LibItem): string => { const { codeQueryStr } = libItem.querys; const codeNode = document.querySelector(codeQueryStr); if (!codeNode) return ""; @@ -24,7 +25,8 @@ const getCode = (libItem: LibItem): string => { ? (codeNode.dataset.clipboardText as string) : codeNode.innerText.replace("复制", ""); - if (codeText?.includes("FC2")) return codeText.split("-")[1]; + if (codeText.includes("FC2")) return codeText.split("-")[1]; + if (codeText.startsWith(SP_PREFIX)) return codeText.substring(3); return codeText; }; @@ -39,7 +41,7 @@ interface TResponse { readonly finalUrl: string; } -const gmFetch = ({ url }: { url: string }): Promise => { +export const gmFetch = ({ url }: { url: string }): Promise => { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method: "GET", @@ -50,4 +52,4 @@ const gmFetch = ({ url }: { url: string }): Promise => { }); }; -export { isCaseInsensitiveEqual, isErrorCode, getCode, gmFetch, regEnum as regEnum }; + diff --git a/src/utils/siteList.ts b/src/utils/siteList.ts index 086c205..4d7401f 100644 --- a/src/utils/siteList.ts +++ b/src/utils/siteList.ts @@ -297,6 +297,7 @@ export const siteList: SiteItem[] = [ fetcher: "get", domQuery: {}, method: print, + codeFormater: (preCode) => (preCode.startsWith("MIUM") ? `${SP_PREFIX}${preCode}` : preCode), }, { name: "JavDB", @@ -323,3 +324,6 @@ export const siteList: SiteItem[] = [ method: print, }, ]; + +/** bus 里有些以 '300MIUM' 开头,要处理掉这个 300 */ +export const SP_PREFIX = "300" as const;