Skip to content

Commit

Permalink
Partially fix Japanse card serch (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
uu1t committed Aug 14, 2018
1 parent 9201e76 commit da2d723
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/wikia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export async function _fetchImageUrl(title: string): Promise<string | null> {
return null;
}

const excludeTitlePatterns = [
/^List of /,
/^(Chapter|Episode) Card Galleries:/,
/ \((?!card).*\)$/
];

export async function _searchTitle(name: string): Promise<string | null> {
const url = endpoints.search + encodeURIComponent(name);
const response = await fetch(url);
Expand All @@ -47,7 +53,10 @@ export async function _searchTitle(name: string): Promise<string | null> {
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;
}
}
Expand Down

0 comments on commit da2d723

Please sign in to comment.