import { selectAll, select } from 'd3-selection'; /* Uses the Mediawiki API to simply display the contents of a wiki page. Makes use of the following API calls: * https://www.mediawiki.org/wiki/API:Parsing_wikitext */ var main = select("#content"), title = window.location.hash ? window.location.hash.substring(1) : "Bienvenue_à_l’erg", baseurl = "/mw/api.php?action=parse&format=json&formatversion=2title=", url = baseurl; async function get_json (url) { var resp = await fetch(url); return await resp.json(); } function url_for_title (title) { return "/w/"+encodeURI(title.replace(/ /g, "_")); } async function load () { let count = 0, debugloopcount = 0; while (count < NUM_FILES) { console.log("starting loop", debugloopcount, "count", count, "url", url); let resp = await fetch(url), data = await resp.json(), allimages = data.query.allimages, useimages = []; // console.log("got data", data.query.allimages.length); // For each image: // Use API:Imageinfo request/get the URL to a thumbnail image // for (var i=0, l=allimages.length; id.imageinfo.thumburl && (d.imageusage.length > 0)); let items = main.selectAll("div.file") .data(useimages, d=>d.title) .enter() .append("div") .attr("class", "file") .append("a") .attr("href", d=>url_for_title(d.imageusage[d.imageusage.length-1].title)) .attr("target", "wikiframe") .append("img") .attr('src', d=>d.imageinfo.thumburl); if (data.continue) { url = baseurl+"&aicontinue="+data.continue.aicontinue; } count += useimages.length; debugloopcount += 1; // if (debugloopcount >= 5) break; } } document.addEventListener("DOMContentLoaded", load); document.querySelector("a#more").addEventListener("click", function (e) { e.preventDefault(); load(); });