Autofill Squirdle filters
Squirdle is a fun wordle-like with a Pokémon theme. This bookmarklet makes typing in the filters quicker :)
Bookmarklet
Drag the following link to your bookmark bar!
Autofill SquirdleOr add this code to a bookmark:
javascript:(()=>{(()=>{const u=document.querySelector("#guess"),o=Array.from(document.querySelectorAll("#guesses [id^=guess]")).map(e=>{const r=Array.from(e.querySelectorAll(".emoji")).map(t=>t.src.match(/\/(\w+)\.png$/)[1]),s=pokedex[e.querySelector(".guess").textContent];return{emojis:r,values:s}}).reduce((e,r)=>(r.emojis.forEach((s,t)=>{s==="wrong"?(e[t][s]===void 0&&(e[t][s]=new Set),e[t][s].add(r.values[t]||"None")):(s==="correct"||e[t][s]===void 0||s==="up"&&r.values[t]>e[t][s]||s==="down"&&r.values[t]<e[t][s]||s==="wrongpos")&&(e[t][s]=r.values[t])}),e),[{},{},{},{},{}]),n=["gen","type","type","height","weight"],l=Array.from(new Set(o.flatMap((e,r)=>{if(n[r]==="type"){const s=[];return e.wrongpos!==void 0&&s.push(`${n[r]}:${e.wrongpos||"None"}`),e.correct!==void 0&&s.push(`${n[r]}:${e.correct||"None"}`),e.wrong&&s.push(...Array.from(e.wrong).map(t=>`${n[r]}!${t}`)),s}else return e.correct!==void 0?[`${n[r]}:${e.correct}`]:Object.entries(e).flatMap(([s,t])=>{switch(s){case"up":return`${n[r]}>${t}`;case"down":return`${n[r]}<${t}`;default:return[]}})})));u.value=l.join(" "),u.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0}))})();})();
Full code available below:
type GuessMap = {
correct?: string | number
wrongpos?: string
wrong?: Set<string>
up?: number
down?: number
}
declare const pokedex: Record<string, [number, string, string, number, number]>
;(() => {
const guessEl: HTMLInputElement = document.querySelector("#guess")
const guesses = Array.from(
document.querySelectorAll("#guesses [id^=guess]"),
).map((el) => {
const emojis = Array.from(
el.querySelectorAll<HTMLImageElement>(".emoji"),
).map((em) => em.src.match(/\/(\w+)\.png$/)[1])
const values = pokedex[el.querySelector(".guess").textContent]
return { emojis, values }
})
const reduced = guesses.reduce(
(acc, curr) => {
curr.emojis.forEach((emoji, index) => {
if (emoji === "wrong") {
if (acc[index][emoji] === undefined) {
acc[index][emoji] = new Set()
}
acc[index][emoji].add((curr.values[index] as string) || "None")
} else if (emoji === "correct" || acc[index][emoji] === undefined) {
acc[index][emoji] = curr.values[index]
} else if (emoji === "up" && curr.values[index] > acc[index][emoji]) {
acc[index][emoji] = curr.values[index] as number
} else if (emoji === "down" && curr.values[index] < acc[index][emoji]) {
acc[index][emoji] = curr.values[index] as number
} else if (emoji === "wrongpos") {
acc[index][emoji] = curr.values[index] as string
}
})
return acc
},
<GuessMap[]>[{}, {}, {}, {}, {}],
)
const names = ["gen", "type", "type", "height", "weight"] as const
const values = Array.from(
new Set(
reduced.flatMap((res, index) => {
if (names[index] === "type") {
const arr = []
if (res.wrongpos !== undefined) {
arr.push(`${names[index]}:${res.wrongpos || "None"}`)
}
if (res.correct !== undefined) {
arr.push(`${names[index]}:${res.correct || "None"}`)
}
if (res.wrong) {
arr.push(
...Array.from(res.wrong).map((type) => `${names[index]}!${type}`),
)
}
return arr
} else if (res.correct !== undefined) {
return [`${names[index]}:${res.correct}`]
} else {
return Object.entries(res).flatMap(([k, v]) => {
switch (k) {
case "up":
return `${names[index]}>${v}`
case "down":
return `${names[index]}<${v}`
default:
return []
}
})
}
}),
),
)
guessEl.value = values.join(" ")
guessEl.dispatchEvent(
new Event("input", {
bubbles: true,
cancelable: true,
}),
)
})()