Skip to content

Commit

Permalink
Merge pull request #3 from kojole/2-partially-fix-japanese-card-search
Browse files Browse the repository at this point in the history
Partially fix Japanse card serch (#2)
  • Loading branch information
uu1t authored Aug 14, 2018
2 parents 9201e76 + da2d723 commit f67679c
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 f67679c

Please sign in to comment.