Skip to content

Instantly share code, notes, and snippets.

@treischl
Created March 10, 2017 19:20
Show Gist options
  • Select an option

  • Save treischl/0333b1c4725cb2bb23d5e76d018496f5 to your computer and use it in GitHub Desktop.

Select an option

Save treischl/0333b1c4725cb2bb23d5e76d018496f5 to your computer and use it in GitHub Desktop.

Revisions

  1. treischl created this gist Mar 10, 2017.
    50 changes: 50 additions & 0 deletions add-egg-distances-to-egg-tier-table.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    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();
    })
    });