User:SD0001/edits-since-decline.js

/** * Script to show an [edits since this decline] link on the latest decline banner * on an AFC draft. * Per Wikipedia_talk:WikiProject_Articles_for_creation * * Installation: add the following to your common.js page importScript('User:SD0001/edits-since-decline.js') // User:SD0001/edits-since-decline.js * */

$.when(	$.ready, 	mw.loader.using(['ext.gadget.morebits', 'ext.gadget.libExtraUtil', 'mediawiki.api']) ).then(function {

if (mw.config.get('wgCanonicalNamespace') !== 'Draft' || 		!$('.ombox-notice td.mbox-text:contains("Submission declined on ")').length) return; new Morebits.wiki.page(Morebits.pageNameNorm).load(function(pageobj) {		var templates = extraJs.parseTemplates(pageobj.getPageText);		var declinets = templates.find(function(t) { return t.name === 'AFC submission' && t.parameters[0].value === 'd'; }).getParam('declinets').value;		new mw.Api.get({ "action": "query", "format": "json", "prop": "revisions", "titles": Morebits.pageNameNorm, "formatversion": "2", "rvprop": "ids|timestamp", "rvlimit": "2", "rvstart": declinets, "rvdir": "newer" }).then(function(json) { var revid = json.query.pages[0].revisions[0].revid; var link = mw.util.getUrl(Morebits.pageNameNorm, {		   	diff: 'cur', 		    	oldid: revid		    }); var span = $('.ombox-notice td.mbox-text span:contains("Submission declined on ")')[0]; $(span).append(		   	' ',				$('').text('[edits since this decline]').attr('href', link)			); });

}); });