Created
August 21, 2025 23:12
-
-
Save irisfofs/4bba493efd936a20cebb07c374aab468 to your computer and use it in GitHub Desktop.
Added type coverage script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * - Paste into console of https://pokemondb.net/tools/type-coverage | |
| * - Select base types. | |
| * - Run `resultsFromAddingOneType()` and observe output. | |
| */ | |
| typeButtons = new Map(Array.from(document.querySelectorAll('.type-button')).map( | |
| typeButton => [typeButton.textContent.trim(), typeButton] | |
| )); | |
| calculateButton = document.getElementById('calc-coverage'); | |
| statCounts = Array.from(document.querySelectorAll('.stat-summary-count')); | |
| ALL_TYPES = new Set(typeButtons.keys()); | |
| function selectTypes(types) { | |
| for (const [name, button] of typeButtons) { | |
| button.classList.toggle('selected', types.has(name)); | |
| } | |
| } | |
| async function calculate() { | |
| calculateButton.click(); | |
| // Wait until the text stops saying Calculating... | |
| const pConsole = document.querySelector('p.console'); | |
| do { | |
| await new Promise(resolve => setTimeout(resolve, 1)); | |
| } while (pConsole.textContent === 'Calculating...'); | |
| return statCounts.map(span => Number(span.textContent)); | |
| } | |
| function getSelectedTypes() { | |
| const selected = []; | |
| for (const [name, typeButton] of typeButtons) { | |
| if (!typeButton.classList.contains('selected')) continue; | |
| selected.push(name); | |
| } | |
| return selected; | |
| } | |
| // Return a list of effectivenesses after trying each other type. | |
| async function resultsFromAddingOneType() { | |
| const baseTypes = getSelectedTypes(); | |
| const baseTypesSet = new Set(baseTypes); | |
| const baseEff = await calculate(); | |
| const effMap = new Map(); | |
| for (const t of ALL_TYPES.difference(baseTypesSet)) { | |
| typeButtons.get(t).classList.add('selected'); | |
| const effectivenesses = await calculate(); | |
| effMap.set(t, effectivenesses); | |
| typeButtons.get(t).classList.remove('selected'); | |
| } | |
| // console.log(effMap); | |
| // Sort by super effective count, descending. | |
| const sortedResults = Array.from(effMap.entries()) | |
| .sort(([k1, v1], [k2, v2]) => v2[3] - v1[3]); | |
| const s = baseTypes.length > 1 ? 's' : ''; | |
| const resultHeader = `Base type${s}: ${baseTypes.join(', ')} | |
| Coverage: ${formatEffectiveness(baseEff)} | |
| -------------------------------------- | |
| `; | |
| const resultBody = sortedResults | |
| .map(([typeName, effs]) => formatEffectivenessEntry(typeName, effs)) | |
| .join('\n'); | |
| console.log(resultHeader + resultBody); | |
| // return effMap; | |
| } | |
| function formatEffectivenessEntry(typeName, effs) { | |
| return `${`+${typeName}:`.padEnd(10)} ${formatEffectiveness(effs)}`; | |
| } | |
| function formatEffectiveness(effs) { | |
| // const EFF_NAMES = ['Imm', 'NVE', 'Normal', 'SE']; | |
| const EFF_NAMES = ['×', '−', '+', '++']; | |
| return [0, 1, 2, 3].map(i => `${String(effs[i]).padStart(4)}${EFF_NAMES[i]}`) | |
| .join(', '); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment