Created
March 10, 2017 19:20
-
-
Save treischl/0333b1c4725cb2bb23d5e76d018496f5 to your computer and use it in GitHub Desktop.
Add Distances to Egg Tier Table on https://thesilphroad.com/science/secret-egg-rarity-tiers-pokemon-go
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
| var cellIndices = { | |
| '2KM' : 2, | |
| '5KM' : 3, | |
| '10KM' : 4, | |
| }; | |
| fetch('/egg-distances') | |
| .then(r => r.text()) | |
| .then((respText) => { | |
| let eggs = {}; | |
| let doc = document.createElement('html'); | |
| doc.innerHTML = respText; | |
| [...doc.getElementsByClassName('speciesWrap')].forEach((div) => { | |
| let p = div.getElementsByTagName('p'); | |
| let stats = div.getElementsByClassName('col-xs-6'); | |
| eggs[p[0].innerText.trim().replace('#', '')] = { | |
| distance: p[1].innerText.trim().toUpperCase(), | |
| name: p[2].innerText.trim(), | |
| perfect: stats[1].innerText.trim(), | |
| worst: stats[3].innerText.trim(), | |
| }; | |
| }); | |
| let table = document.getElementsByTagName('table')[1]; | |
| let rows = [...table.getElementsByTagName('tr')]; | |
| Object.keys(cellIndices).forEach((distText) => { | |
| let th = document.createElement('th'); | |
| th.innerText = distText; | |
| rows[0].appendChild(th); | |
| }); | |
| rows.slice(1, 5).forEach((row) => { | |
| for (let i = 0; i < 3; i ++) { | |
| let td = document.createElement('td'); | |
| let p = document.createElement('p'); | |
| td.appendChild(p); | |
| row.appendChild(td); | |
| } | |
| [...row.getElementsByTagName('img')].forEach((img) => { | |
| let ndx = /\/(\d+).png$/.exec(img.src)[1]; | |
| if (ndx.length === 1) ndx = `00${ndx}`; | |
| if (ndx.length === 2) ndx = `0${ndx}`; | |
| let egg = eggs[ndx]; | |
| img.remove(); | |
| row.cells[cellIndices[egg.distance]].getElementsByTagName('p')[0].appendChild(img); | |
| img.style = 'margin:-16px -12px; width:75px'; | |
| img.title = `${egg.name.toUpperCase()}\nPerfect: ${egg.perfect}\nWorst: ${egg.worst}`; | |
| }); | |
| }); | |
| rows.forEach((row) => { | |
| row.cells[1].remove(); | |
| }) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment