diff --git a/src/utils/index.ts b/src/utils/index.ts index 89fdd27..f240b7f 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,35 +1,6 @@ import { GM_xmlhttpRequest } from "$"; import { type LibItem } from "./libSites"; import { SP_PREFIX } from "./siteList"; - -export const isCaseInsensitiveEqual = (str1: string, str2: string) => { - return str1.toLowerCase() === str2.toLowerCase(); -}; - -export const isErrorCode = (resCode: number) => { - return [404, 403].includes(resCode); -}; - -export const regEnum = { - subtitle: /(中文|字幕|subtitle)/, - leakage: /(无码|無碼|泄漏|Uncensored)/, -}; - -export const getCode = (libItem: LibItem): string => { - const { codeQueryStr } = libItem.querys; - const codeNode = document.querySelector(codeQueryStr); - if (!codeNode) return ""; - - const codeText = - libItem.name === "javdb" - ? (codeNode.dataset.clipboardText as string) - : codeNode.innerText.replace("复制", ""); - - if (codeText.includes("FC2")) return codeText.split("-")[1]; - if (codeText.startsWith(SP_PREFIX)) return codeText.substring(3); - - return codeText; -}; interface TResponse { readonly responseHeaders: string; readonly readyState: 0 | 1 | 2 | 3 | 4; @@ -71,3 +42,46 @@ export const gmPost = ({ }); }; +export const isCaseInsensitiveEqual = (str1: string, str2: string) => { + return str1.toLowerCase() === str2.toLowerCase(); +}; + +export const isErrorCode = (resCode: number) => { + return [404, 403].includes(resCode); +}; + +export const getCode = (libItem: LibItem): string => { + const { codeQueryStr } = libItem.querys; + const codeNode = document.querySelector(codeQueryStr); + if (!codeNode) return ""; + + const codeText = + libItem.name === "javdb" + ? (codeNode.dataset.clipboardText as string) + : codeNode.innerText.replace("复制", ""); + + if (codeText.includes("FC2")) return codeText.split("-")[1]; + if (codeText.startsWith(SP_PREFIX)) return codeText.substring(3); + + return codeText; +}; + +export const regEnum = { + subtitle: /(中文|字幕|subtitle)/, + leakage: /(无码|無碼|泄漏|Uncensored)/, +}; + +export const tagsQuery = ({ + leakageText, + subtitleText, +}: { + leakageText: string; + subtitleText: string; +}) => { + const hasLeakage = regEnum.leakage.test(leakageText); + const hasSubtitle = regEnum.subtitle.test(subtitleText); + const tags = []; + if (hasLeakage) tags.push("无码"); + if (hasSubtitle) tags.push("字幕"); + return tags.join(" "); +}; diff --git a/src/utils/siteList.ts b/src/utils/siteList.ts index 1ba8443..4682190 100644 --- a/src/utils/siteList.ts +++ b/src/utils/siteList.ts @@ -81,7 +81,7 @@ export const siteList: SiteItem[] = [ // 标签区的第一个一般是字幕标签 subQuery: '.space-y-2 a.text-nord13[href="https://missav.com/chinese-subtitle"]', // 有个「切換無碼」按钮,藏在分享按钮旁边…… - // leakQuery: ".order-first div.rounded-md a[href]:last-child", + leakQuery: ".order-first div.rounded-md a[href]:last-child", }, }, { diff --git a/src/utils/xhr.ts b/src/utils/xhr.ts index d890a48..0ec58f7 100644 --- a/src/utils/xhr.ts +++ b/src/utils/xhr.ts @@ -1,4 +1,4 @@ -import { gmGet, isCaseInsensitiveEqual, isErrorCode, regEnum } from "./"; +import { gmGet, isCaseInsensitiveEqual, isErrorCode, regEnum, tagsQuery } from "./"; import type { DomQuery_get, DomQuery_parser, SiteItem } from "./siteList"; export type FetchResult = { @@ -24,8 +24,7 @@ function videoPageParser(responseText: string, { subQuery, leakQuery, videoQuery const videoNode = videoQuery ? doc.querySelector(videoQuery) : true; return { isSuccess: !!videoNode, - hasSubtitle: regEnum.subtitle.test(subNodeText), - hasLeakage: regEnum.leakage.test(linkNodeText), + tag: tagsQuery({ leakageText: linkNodeText, subtitleText: subNodeText }), }; } @@ -60,17 +59,12 @@ function serachPageParser( return { isSuccess: false }; } const targetLinkText = linkNode.href.replace(linkNode.hostname, siteHostName); - const hasLeakage = regEnum.leakage.test(titleNodeText); - const hasSubtitle = regEnum.subtitle.test(titleNodeText); - const tags = []; - if (hasLeakage) tags.push("无码"); - if (hasSubtitle) tags.push("字幕"); return { isSuccess: true, targetLink: targetLinkText, multipResLink: searchPageLink, multipleRes: titleNodes.length > 1, - tag: tags.join(" "), + tag: tagsQuery({ leakageText: titleNodeText, subtitleText: titleNodeText }), }; }