User:Dorumin/dpl.​js

// A DPL library that doesn't suck.  window.dpl = {};

dpl.api = new mw.Api; dpl.step = 500;

dpl.format = function(params) { return ' ' + Object.entries(params).map(kv => kv.join('=')).join('\n') + ' ' };

dpl.get = function(params) { return dpl.api.get({       action: 'parse',        disablepp: true,        text: dpl.format(params)    }) .then(function(d) {       return d.parse.text['*'];    }) .then(function(content) {		var container = document.createElement('div');		container.innerHTML = content;		console.log(container);       return Array.from(container.firstChild.children).map(function(elem) { return elem.firstChild.getAttribute('title'); });   }); };

dpl.query = function(params) { return dpl.get(params); };

dpl._callagain = function(params, offset, sum) { return dpl.get($.extend(params, { offset: offset })).then(function(results) {       sum = sum.concat(results);        if (sum.length < offset + (params.count || dpl.step)) {            return sum;        }        return dpl._callagain(params, offset + dpl.step, sum);    }); };

dpl.query.recursive = function(params) { return dpl._callagain(params, 0, []); };