From 59a83bdb123629ef07d6dfabd6cbf2df38b0a660 Mon Sep 17 00:00:00 2001 From: mrbunker Date: Sat, 29 Jul 2023 16:23:09 +0800 Subject: [PATCH] feat: new site 18av --- src/utils/index.ts | 9 ++++++++- src/utils/siteList.ts | 8 ++++++++ src/utils/xhr.ts | 14 +++++--------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index fca9656..2ee1208 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -4,9 +4,16 @@ import { type LibItem } from "./libSites"; const isCaseInsensitiveEqual = (str1: string, str2: string) => { return str1.toLowerCase() === str2.toLowerCase(); }; + const isErrorCode = (resCode: number) => { return [404, 403].includes(resCode); }; + +const regEnum = { + subtitle: /(中文|字幕|subtitle)/, + leakage: /(无码|無碼|泄漏|Uncensored)/, +}; + const getCode = (libItem: LibItem): string => { const { codeQueryStr } = libItem.querys; const codeNode = document.querySelector(codeQueryStr); @@ -43,4 +50,4 @@ const gmFetch = ({ url }: { url: string }): Promise => { }); }; -export { isCaseInsensitiveEqual, isErrorCode, getCode, gmFetch }; +export { isCaseInsensitiveEqual, isErrorCode, getCode, gmFetch, regEnum as regEnum }; diff --git a/src/utils/siteList.ts b/src/utils/siteList.ts index d74b868..0685656 100644 --- a/src/utils/siteList.ts +++ b/src/utils/siteList.ts @@ -281,6 +281,14 @@ export const siteList: SiteItem[] = [ domQuery: { linkQuery: ".well>a[href]", titleQuery: ".well>a[href]>span.video-title" }, method: print, }, + { + name: "18av", + hostname: "18av.mm-cg.com", + url: "https://18av.mm-cg.com/zh/fc_search/all/{{code}}/1.html", + fetcher: "parser", + domQuery: { linkQuery: ".posts h3>a[href]", titleQuery: ".posts h3>a[href]" }, + method: print, + }, { name: "JavBus", disableLibItemName: "javbus", diff --git a/src/utils/xhr.ts b/src/utils/xhr.ts index 20dc4f7..4b3d87c 100644 --- a/src/utils/xhr.ts +++ b/src/utils/xhr.ts @@ -1,4 +1,4 @@ -import { gmFetch, isCaseInsensitiveEqual, isErrorCode } from "@/utils"; +import { gmFetch, isCaseInsensitiveEqual, isErrorCode, regEnum } from "@/utils"; import type { DomQuery_get, DomQuery_parser, SiteItem } from "./siteList"; export type FetchResult = { @@ -9,8 +9,6 @@ export type FetchResult = { msg: string; }; -const leakReg = /(无码|無碼|泄漏|Uncensored)/; - /** 针对视频播放页进行解析,寻找字幕等信息 */ function videoPageParser(responseText: string, { subQuery, leakQuery, videoQuery }: DomQuery_get) { const doc = new DOMParser().parseFromString(responseText, "text/html"); @@ -26,8 +24,8 @@ function videoPageParser(responseText: string, { subQuery, leakQuery, videoQuery const videoNode = videoQuery ? doc.querySelector(videoQuery) : true; return { isSuccess: !!videoNode, - hasSubtitle: subNodeText.includes("字幕") || subNodeText.includes("subtitle"), - hasLeakage: leakReg.test(linkNodeText), + hasSubtitle: regEnum.subtitle.test(subNodeText), + hasLeakage: regEnum.leakage.test(linkNodeText), }; } @@ -55,13 +53,11 @@ function serachPageParser( if (isSuccess) { const targetLinkText = linkNode.href.replace(linkNode.hostname, siteHostName); - - const hasSubtitle = titleNodeText.includes("字幕") || titleNodeText.includes("subtitle"); return { isSuccess: true, targetLink: targetLinkText, - hasLeakage: leakReg.test(titleNodeText), - hasSubtitle, + hasLeakage: regEnum.leakage.test(titleNodeText), + hasSubtitle: regEnum.subtitle.test(titleNodeText), }; } else { return { targetLink: "", isSuccess: false, hasSubtitle: false, hasLeakage: false };