Jump to content

User:Theleekycauldron/sandbox.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Theleekycauldron (talk | contribs) at 05:38, 13 January 2022 (no function tag). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
function convertToDate2(str){
    str = str.split(", ");
    str[0] = str[0].split(":");
    str[1] = str[1].split(" ");
    str[1][1] = dict[str[1][1]];
    return new Date(str[1][2],str[1][1],str[1][0],str[0][0],str[0][1]);
}

async function writeToStats(res,papp){
	let statspagetext;
	let statspage = api.get( {
			prop: 'revisions',
			rvprop: 'content',
			rvlimit: 1,
			indexpageids: true,
			titles: "Wikipedia:Did_you_know/Statistics"
		}).then( function (data) {
		var q = data.query,
			id = q && q.pageids && q.pageids[0],
			pg = id && q.pages && q.pages[ id ],
			rv = pg && pg.revisions;
		if ( rv && rv[0] && rv[0]['*'] ) {
			statspagetext = rv[0]['*'];
		}
	await statspage;
	let monthyear;
	if (mw.config.get('wgPageName') == "Wikipedia:Recent_additions"){
		if (papp.length == 0){
			throw new Error("Howdy there, pardner! Looks like you've tried to run a this ol' horse on a page with no manure to shovel for this month, and that just don't make jack. Check back tomorruh, maybe we can higgle over something from the hoosegow. Now, pull in your horns and light a shuck, wouldya?")
		} else {
			let date = convertToDate2(papp[0]);
			monthyear = date.getUTCFullYear() + " " +months(date.getUTCMonth())
		}
	} else {
		let s = mw.config.get('wgPageName').split("/");
		monthyear = s[2] + " " + s[1];
	}
	
}
writeToStats("",[])