User:Theleekycauldron/User contributions.js

From Wikipedia, the free encyclopedia
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.
console.log("howdy!");
async function query(user,extra){
    var q = await querying(user,null);
    var res = q.query.usercontribs;
    for (var i=0; i<extra; i++){
        q = await querying(user,q.continue.uccontinue);
        console.log(q);
        res = q.query.usercontribs.concat(res);
    }
    return res;
}
async function querying(user,start){
	var url = "https://en.wikipedia.org/w/api.php"; 
	let usercontrib;
	var params = {
		action:      "query",
		format:      "json",
		list:        "usercontribs",
		ucuser:      user,
		uclimit:     "500",
		ucnamespace: "3",
		ucprop:      "title|comment"
	};
    if (start !== null){
        params.uccontinue = start;
    }
	url = url + "?origin=*";
	Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});

	await fetch(url).then(function(response){return response.json();})
    .then(function(response) {
        usercontrib = response;
        
    })
    .catch(function(error){console.log(error);});
	return usercontrib;
}