fix: tag not displaying

This commit is contained in:
mrbunker
2024-09-21 16:38:32 +08:00
parent 7c0ea49fb1
commit ea9e20931a
3 changed files with 47 additions and 39 deletions

View File

@@ -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<HTMLElement>(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<HTMLElement>(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(" ");
};

View File

@@ -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",
},
},
{

View File

@@ -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<HTMLElement>(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 }),
};
}