From da2d7230a5c8d50a7f8b27c1f035f9276358d1b0 Mon Sep 17 00:00:00 2001 From: Yuichi Tanikawa Date: Tue, 14 Aug 2018 14:55:38 +0900 Subject: [PATCH] Partially fix Japanse card serch (#2) --- src/wikia.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wikia.ts b/src/wikia.ts index 7c9eaea..61bb666 100644 --- a/src/wikia.ts +++ b/src/wikia.ts @@ -37,6 +37,12 @@ export async function _fetchImageUrl(title: string): Promise { return null; } +const excludeTitlePatterns = [ + /^List of /, + /^(Chapter|Episode) Card Galleries:/, + / \((?!card).*\)$/ +]; + export async function _searchTitle(name: string): Promise { const url = endpoints.search + encodeURIComponent(name); const response = await fetch(url); @@ -47,7 +53,10 @@ export async function _searchTitle(name: string): Promise { const $els = html.querySelectorAll('.result h1 .result-link'); for (const $el of $els) { const title = $el.textContent; - if (title && !title.match(/^List of /)) { + if ( + title && + excludeTitlePatterns.every(pattern => !title.match(pattern)) + ) { return title; } }