MediaWiki:Common.js/User:Fumple/EditCount.js

// //

//Load get params var url = new URL(window.location.href); var user = url.searchParams.get("user");

var alledits = []; $("#controls").append(' '); $("#load").css("display", "none"); $("#user-edits-button").click(function {    $("#user-edits-name").attr("disabled", "")    $("#user-edits-button").attr("disabled", "")    alledits = [];    new mw.Api.get({ "action": "query", "list": "usercontribs", "uclimit": "max", "ucprop": "tags|title", "ucuser": $("#user-edits-name")[0].value })       .done(done)        .fail(function (err) { $("#load").html("An unexpected error occured!"); $("#load").css("display", ""); console.log(err) }) }) if(user != null){ $("#user-edits-name")[0].value = user; $("#user-edits-button").click; } function done(data) { alledits = alledits.concat(data.query.usercontribs); if (data.continue != null) { $("#load").html(`Loading edits... (${alledits.length}/?) `); new mw.Api.get({           "action": "query",            "list": "usercontribs",            "uclimit": "max",            "ucprop": "tags|title",            "ucuser": $("#user-edits-name")[0].value,            "uccontinue": data.continue.uccontinue        }) .done(done) .fail(function (err) {               $("#load").html("An unexpected error occured!");                $("#load").css("display", "");                console.log(err)            }) return; }   var noredirects = alledits.filter(function (a) { return !a.tags.includes("mw-new-redirect") }); var filtered = noredirects.filter(function (a) { return a.ns != 2 && a.ns != 3 }).length; var page = noredirects.filter(function (a) { return a.ns % 2 == 0 }).length; var talk = noredirects.filter(function (a) { return a.ns % 2 == 1 }).length; var mainspace = noredirects.filter(function (a) { return a.ns == 0 }).length; var mainspacetalk = noredirects.filter(function (a) { return a.ns == 1 }).length; var meta = noredirects.filter(function (a) { return a.ns == 4 || a.ns == 12 }).length; var metatalk = noredirects.filter(function (a) { return a.ns == 5 || a.ns == 13 }).length; var mediawiki = noredirects.filter(function (a) { return a.ns == 8 }).length; var mediawikitalk = noredirects.filter(function (a) { return a.ns == 9 }).length; $("#user-edits-name").attr("disabled", null) $("#user-edits-button").attr("disabled", null) $("#load").html(alledits.length > 0 ?        `Found ${alledits.length} edits                     ${noredirects.length} (${Math.floor(noredirects.length / alledits.length * 100)}%) edits that aren't new redirects            (The following edit counts exclude new redirect creations)            ${filtered     } (${Math.floor(filtered      / noredirects.length * 100)}%) edits outside the user page/talk namespace            ${page         } (${Math.floor(page          / noredirects.length * 100)}%) page edits (excludes talk pages)            ${talk         } (${Math.floor(talk          / noredirects.length * 100)}%) talk page edits            ${mainspace    } (${Math.floor(mainspace     / noredirects.length * 100)}%) mainspace edits</li>            ${mainspacetalk} (${Math.floor(mainspacetalk / noredirects.length * 100)}%) mainspace talk page edits</li> ${meta        } (${Math.floor(meta          / noredirects.length * 100)}%) meta edits (Inkipedia:, Help:)</li> ${metatalk    } (${Math.floor(metatalk      / noredirects.length * 100)}%) meta talk page edits (Inkipedia talk:, Help talk:)</li> ${mediawiki   } (${Math.floor(mediawiki     / noredirects.length * 100)}%) MediaWiki: edits</li> ${mediawikitalk} (${Math.floor(mediawikitalk / noredirects.length * 100)}%) MediaWiki talk: edits</li> </ul>` : "The user either doesn't exist or didn't make any edits that are visible to you");   $("#load").css("display", ""); }