Jump to content

User:DannyS712 test/nuke.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DannyS712 test (talk | contribs) at 03:45, 10 March 2019 (start converting). 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.
// Install this version with:
// <code><nowiki>		{{subst:Iusc|User:DannyS712/Nuke requester.js}}																</nowiki></code>
// or with
// <code><nowiki>		importScript( 'User:DannyS712/Nuke requester.js' ); // Backlink: [[User:DannyS712/Nuke requester.js]] 		</nowiki></code> 
//
// If forking this script, please note my contributions / give me credit
//<nowiki>
$(function (){
var rn_config = {
	name: '[[User:DannyS712/Nuke requester|Nuke requester]]',
	version: 1.0,
	debug: true
};
var rn_summary = 'Request a nuke with ' + rn_config.name + ' (version ' + rn_config.version + ')';

mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.Title', 'mediawiki.RegExp'], function() {
	if ( mw.config.get( 'wgPageName' ) == "Wikipedia:Requests_for_undeletion") {
		importScript( 'User:DannyS712 test/page.js' );
    	RNK_init();
	}
} );
function request_Nuke( request ){
	var requesting_page = mw.config.get( 'wgPageName' );
	var old = get_page( requesting_page );
	var new_page = old + request;
	set_page( requesting_page, new_page, rn_summary, false );
}
function make_request() {
	var page = ["placeholder"], type = ["placeholder"], reason = ["placeholder"];
	$('.RNK-page').each(function () {page.push(this.value);});
	$('.RNK-type').each(function () {type.push(this.value);});
	$('.RNK-reason').each(function () {reason.push(this.value);});
	page = page[1];
	type = type[1];
	reason = reason[1];
	
	if (rn_config.debug) console.log ( page, type, reason );
	var output = "== " + page + " ==\n\n";
	if (type == "G13") output = output + "{{SAFESUBST:Refund/G13|" + page + "}}";
	else output = output + "{{subst:refund|1= " + page + " |2= " + reason + " }}";
	$("#RNK-interface-content").css({
      "min-height": "7em",
      "width" : "875px",
      "height" : "200px",
    });
	$("#RNK-interface-content").empty();
	$("#RNK-interface-header").empty();
	$("#RNK-interface-header").text("Request undeletion");
	$('.RNK-tip').remove();
	$("#RNK-interface-content").append(
		$('<button>').attr('id','RNK-submit').text('Submit request'),
		$('<label>').attr('id','RNK-submit').text(''),
		$('<textarea>').css({'resize':'none'}).attr({'id':'RNK-output','readonly':'true','rows':'5','cols':'25'}).text(output)
	);
	$("#RNK-interface-footer").append( $('<button>').attr('id', 'RNK-back').css('margin-left','1em').text('Back') );
	$('#RNK-submit').click(function() {
		var request = "\n\n" + output;
        $('#RNK-back').remove();
        $('#RNK-interface-content').empty();
        $('#RNK-interface-content').append( $('<label>').attr('id','RNK-submitting').text('\nSubmitting...') );
		if (rn_config.debug) console.log ( request );
		request_Nuke ( request );
	});
	$('#RNK-back').click(function () {
        $('#RNK-back').remove();
        $("#RNK-interface-content").css({
    		"min-height": "7em",
		    "width" : "875px",
		    "height" : "200px",
	    });
        screen1();
    });
}
function screen1() {
	$("#RNK-interface-header, #RNK-interface-content, #RNK-interface-footer").empty();
	$("#RNK-interface-header").text("Request undeletion*");
	$("#RNK-interface-footer").append($('<button>').attr('id', 'RNK-cancel').text('Close'));
	$('#RNK-cancel').click(function() {$('#RNK-modal').remove();});
	$("#RNK-interface-footer").prepend(
		$('<small>').attr('class','RNK-tip').text('*For more information, see ').append($('<a>').attr('href','//en.wikipedia.org/wiki/WP:CSDRFU').text('undeleting speedily-deleted pages')),
		$('<br>').attr('class','RNK-tip'),
		$('<small>').attr('class','RNK-tip').text('**Leave blank if you are requesting a G13 undeletion'),
		$('<br>').attr('class','RNK-tip')
	);
	$("#RNK-interface-content").append(
		$('<div>').css('margin-bottom','0.5em').append(
			$('<label>').text('Page: '),
			$('<input>').attr({'type':'text','class':'RNK-page'})
    	),
    	$('<div>').css('margin-bottom','0.5em').append(
	        $('<label>').text( 'Refund type: '),
	        $('<select>').attr('class','RNK-type')
	         .append($("<option>").attr({'value':'G13','selected':'true'}).text('G13'))
	         .append($("<option>").attr('value','Other').text('Other'))
    	),
		$('<div>').css('margin-bottom','0.5em').append(
			$('<label>').text('Reason**: '),
			$('<input>').attr({'type':'text','class':'RNK-reason'})
    	)
    );
    $("#RNK-interface-content").append($('<button>').attr('id','RNK-request').text('Preview request'));
    $('#RNK-request').click(function() {make_request()});
}
function RNK_init() {
  mw.util.addPortletLink('p-cactions', 'javascript:void(0)', 'Undelete', 'aca-RNK', 'Easily request undeletion', null);
  $('#aca-RNK').on('click', function() {
    $('body').prepend('<div id="RNK-modal">'+
      '<div id="RNK-interface">'+
        '<h4 id="RNK-interface-header"></h4>'+
        '<hr>'+
        '<div id="RNK-interface-content"></div>'+
        '<hr>'+
        '<div id="RNK-interface-footer"></div>'+
      '</div>'+
    '</div>');
    $("#RNK-modal").css({
      "position": "fixed",
      "z-index": "1",
      "left": "0",
      "top": "0",
      "width": "100%",
      "height": "100%",
      "overflow": "hidden",
      "background-color": "rgba(0,0,0,0.4)"
    });
    $("#RNK-interface").css({
      "background-color": "#e8f0ff",
      "margin": "15% auto",
      "padding": "2px 20px",
      "border": "1px solid #888",
      "width": "80%",
      "max-width": "60em",
    });
    $("#RNK-interface-content").css({
      "min-height": "7em",
      "width" : "875px",
      "height" : "200px",
    });
    $("#RNK-interface-footor").css("min-height", "3em");
    screen1();
  });
}
});
//</nowiki>