Jump to content

User:SD0001/edits-since-decline.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.
/**
 * 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#Shortcut_for_viewing_changes_since_last_decline?]]
 * 
 * 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(
		    	' ',
				$('<a>').text('[edits since this decline]').attr('href', link)
			);
		});

	});
	
});