Jump to content

User:Habst/mapLocations.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Habst (talk | contribs) at 01:56, 16 February 2024 (add location fetching code). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//https://umap.openstreetmap.fr/en/map/2024-world-athletics-continental-tour_1025200
// { "type": "FeatureCollection", "features": [...] }
window.level = '';
window.qids ??= {};
window.promises = [...document.querySelector('.wikitable').querySelectorAll('tbody tr')].flatMap(async (tr, i) => {
  if (i > 3) return []
  const tds = tr.querySelectorAll('td');
  if (tds.length === 1) {
    level = tds[0].innerText.split(' ')[0];
    return [];
  }
  const date = new Date(tds[0].querySelector('span').getAttribute('data-sort-value').replace(/^0+/, '').replace(/-0+$/, ''));
  const loctitle = tds[2].querySelector('a').href.split('/').at(-1);
  window.qids[loctitle] ??= await (await fetch(`https://en.wikipedia.org/w/api.php?${new URLSearchParams({action:'query',prop:'pageprops',ppprop:'wikibase_item',format:'json',titles:loctitle})}`)).json();
  const pid = Object.keys(qids[loctitle].query.pages)[0];
  console.log(qids[loctitle])
  const qid = qids[loctitle].query.pages[pid].pageprops.wikibase_item;
  console.log(qid);
  return {
    type: "Feature",
    geometry: {
      type: "Point",
      coordinates: [0,0]
    },
    properties: {
      color: level.toLowerCase(),
      name: tds[1].innerText,
      date,
    }
  }
  console.log(level, tds[1].innerText)
});
await promises[0];