From e2f200cf1678b21177ea2716510c49352369b848 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Sat, 27 Apr 2024 17:31:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A0=87=E7=AD=BE=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/shared/ehentai/normalize-tag.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/shared/ehentai/normalize-tag.ts b/src/shared/ehentai/normalize-tag.ts index ee724d83..00bee809 100644 --- a/src/shared/ehentai/normalize-tag.ts +++ b/src/shared/ehentai/normalize-tag.ts @@ -11,12 +11,10 @@ const tagsFoundBySearch = new Set<`${NamespaceName}:${RawTag}`>(); let useEx = true; /** 访问搜索页面,返回文档内容 */ -async function searchTagImpl(raw: RawTag, setExtendView = false): Promise { - // workaround for blocked keywords https://ehwiki.org/wiki/Gallery_Searching#Search_Limitations - // eg: artist:incognitymous +async function searchTagImpl(ns: NamespaceName | undefined, raw: RawTag, setExtendView: boolean): Promise { const base = `https://${useEx ? 'ex' : 'e-'}hentai.org/`; const search = - `f_search=${encodeURIComponent(`"${raw}"`)}&f_cats=0&f_sfl=on&f_sfu=on&f_sft=on` + + `f_search=${encodeURIComponent(ns ? `${ns}:"${raw}"` : `"${raw}"`)}&f_cats=0&f_sfl=on&f_sfu=on&f_sft=on` + (setExtendView ? '&inline_set=dm_e' : ''); const url = `${base}?${search}`; STATISTICS.tagSearch++; @@ -27,7 +25,7 @@ async function searchTagImpl(raw: RawTag, setExtendView = false): Promise'); if (!isExtendView && !setExtendView) { - return searchTagImpl(raw, true); + return searchTagImpl(ns, raw, true); } return result.data; } catch (ex) { @@ -36,25 +34,31 @@ async function searchTagImpl(raw: RawTag, setExtendView = false): Promise { +async function searchTag(ns: NamespaceName, raw: RawTag, useNs = true): Promise { if (ns === 'rows') return false; - const result = await searchTagImpl(raw, false); + const result = await searchTagImpl(useNs ? ns : undefined, raw, false); const tags = result.matchAll(/
/g); let found = false; for (const tag of tags) { const [, tNs, tRaw] = tag; - if (!isNamespaceName(tNs) || !isRawTag(tRaw)) continue; + if (!isNamespaceName(tNs) || !isRawTag(tRaw)) { + continue; + } if (tRaw === raw && tNs === ns) { found = true; } tagsFoundBySearch.add(`${tNs}:${tRaw}`); } - return found; + if (found || !useNs) return found; + + // workaround for blocked keywords https://ehwiki.org/wiki/Gallery_Searching#Search_Limitations + // eg: artist:incognitymous + return await searchTag(ns, raw, false); } function findSearchCache(ns: NamespaceName, raw: RawTag): boolean {