User:Gryllida/js/deleteLinkInRc.js

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

/* Author : Svetlana Tkachenko svetlana@members.fsf.org
This file is a part of deleteLinkInRc.
Licence: GPLv3+
Description: [beta] adds delete link to 'N' pages in recent changes or block or contribs
Recommends: User:Gryllida/js/showPagePreviewWhenDeleting.js
See also <https://en.wikinews.org/wiki/User:Gryllida/Tasks>.
*/ 

function _addDeleteLink (){
	// new page markers present?
	if($('abbr.newpage')){
		// traverse DOM to the parent element of the new page marker
		$('abbr.newpage').parent().each(function(e){
			// get page title as an attribute
			var title = $(this).attr('data-target-page') || $(this).find('.mw-contributions-title').text();
			
			// construct the deletion url
			var url = 'https://en.wikinews.org/w/index.php?title=$1&action=delete';
			url = url.replace('$1', title);
			
			// add the deletion link
			var button = $('<a></a>', {
				text: 'delete',
				href: url
			}); 
			$(this).append(' [');
			$(this).append(button);
			$(this).append(']');
			var buttonSpam = $('<a></a>', {
				text: 'spam delete',
				href: url + '&wpReason=spam',
			}); 
			$(this).append(' [');
			$(this).append(buttonSpam);
			$(this).append(']');
		});
	}
}

mw.loader.using(['mediawiki.api'], function () {
	"use strict";
	
	// == Quit if this is not main namespace ==
	 var thisPageTitle = mw.config.get( 'wgPageName' );
	 
	// check that it's recent changes or block or contribs page
	if (thisPageTitle == 'Special:RecentChanges' || thisPageTitle.indexOf('Special:Contributions') === 0){
		_addDeleteLink();
	}
	
});