Переглянути джерело

Tweak icon lookup logic to handle special cases

Kirk Trombley 3 роки тому
батько
коміт
23f7560644
1 змінених файлів з 14 додано та 2 видалено
  1. 14 2
      nearest.js

+ 14 - 2
nearest.js

@@ -1,4 +1,15 @@
-const getSprite = pokemon => `https://img.pokemondb.net/sprites/sword-shield/icon/${pokemon}.png`
+const stripForm = ["flabebe", "floette", "florges", "vivillon", "basculin", "furfrou", "magearna"];
+
+const getSprite = pokemon => {
+  pokemon = pokemon
+    .replace("-alola", "-alolan")
+    .replace("-galar", "-galarian")
+    .replace("darmanitan-galarian", "darmanitan-galarian-standard");
+  if (stripForm.find(s => pokemon.includes(s))) {
+    pokemon = pokemon.replace(/-.*$/, "");
+  }
+  return `https://img.pokemondb.net/sprites/sword-shield/icon/${pokemon}.png`;
+}
 
 const titleCase = s => s.charAt(0).toUpperCase() + s.substr(1);
 
@@ -112,7 +123,8 @@ const onUpdate = () => {
     // lookup by pokemon too
     const searchList = document.getElementById("search-list");
     searchList.innerHTML = '';
-    pokemonLookup.search(pokemonName, { limit: 10 })
+    pokemonLookup
+      .search(pokemonName, { limit: 15 })
       .map(({ item }) => ({ ...item, score: totalScorer(item) }))
       .forEach(item => {
         const li = document.createElement("li");