User:Theleekycauldron/DYKPC.js

var users = { "Cwmhiraeth": 0, "Yoninah": 0, "Allen3": 0, "SL93": 0, "theleekycauldron": 0, "Hawkeye7": 0, "Crisco 1492": 0, "BlueMoonset": 0, "PFHLai": 0, "97198": 0,	"PumpkinSky": 0, "Miyagawa": 0, "Panyd": 0, "The Squirrel Conspiracy": 0, "Kavyansh.Singh": 0, "Orlady": 0, "Desertarun": 0, "Narutolovehinata5": 0, "Montanabw": 0, "Gatoclass": 0, "Casliber": 0, "MeegsC": 0, "Vaticidalprophet": 0, "Victuallers": 0, "Z1720": 0, "SSTflyer": 0, "Carabinieri": 0, "Kingsif": 0, "HalfGig": 0, "MPJ-DK": 0, "Amkgp": 0, "Mentoz86": 0, "Valereee": 0, "Redtigerxyz": 0, "RoySmith": 0, "Bruxton": 0, "Cielquiparle": 0 }

var active = ["Cwmhiraeth","SL93","theleekycauldron", "RoySmith","Bruxton"] var aftername = { 'Yoninah': " (Z''L) " } async function search_user(username){ var total = 0; var params = { action: 'query', list: 'search', srnamespace: '10', srsearch: '-insource:\"the result was: \'\'\'promoted\'\'\' by \[\[User:\"'+username+' \"the result was: promoted by '+username+'\" intitle:\"Did you know nominations\"', srinfo: 'totalhits', format: 'json' }	res1 = api.get( params ).done( function ( data ) {		total += data.query.searchinfo.totalhits; 	} ); params = { action: 'query', list: 'search', srnamespace: '10', srsearch: ' insource:\"the result was: \'\'\'promoted\'\'\' by \[\[User:'+username+' "intitle:\"Did you know nominations\"', srinfo: 'totalhits', format: 'json' }	res2 = api.get( params ).done( function ( data ) {		total += data.query.searchinfo.totalhits;	} ); await res1; await res2; return total; }

function numberWithCommas(x) { return x.toString.replace(/\B(?=(\d{3})+(?!\d))/g, ","); }

async function update_dykpc{ for (const key of Object.keys(users)){ users[key] = await search_user(key); console.log(key,users[key]); }	users = Object.entries(users).sort((a, b) => b[1] - a[1]); let lines = []; let activeadd, afteradd; users.forEach((user) => {		activeadd = (active.includes(user[0])?"|a=y":"")		afteradd = ((aftername[user[0]]!=undefined)?("|aftername="+aftername[user[0]]):(""))		lines.push("");	}); let pre = "\n\nThis page lists Wikipedia users by the number of DYK nominations closed and moved to the prep sets. The qualification requirement for this list is 100 promotions; the list functions on the modern system of nomination closing, so substantially impactful users such as BorgQueen were too early for this to accurately display their contributions. Thanks to each and every person who has kept DYK functioning with their time and effort through prep-set building! :)\n\nRows in green denote currently active promoters.\n\n{| class=\"wikitable sortable\"\n|+\n!User\n!count\n!Search links (use these to update manually!)\n";	let post = "\n|}\nIf you want, you can add this cool userbox to your userpage! (The template can be found at Template:User DYK promotions)\n\n"	lines = pre+lines.join("\n")+post	console.log(lines);	var editparams = { action: 'edit', title: "Wikipedia:List of Wikipedians by number of DYK promotions", summary: "Updating list (script)", text: lines, format: 'json' }

api.postWithToken( 'csrf', editparams ).done( function ( data ) {		console.log( data );	} ); await editparams; location.reload(true); return lines }

if (mw.config.get('wgPageName').includes("Wikipedia:List_of_Wikipedians_by_number_of_DYK_promotions")){ $('#bodyContent').prepend('update page :) '); }