Jump to content

User:DannyS712/Refund requester.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.
// Install this version with:
// <code><nowiki>		{{subst:Iusc|User:DannyS712/Refund requester.js}}																</nowiki></code>
// or with
// <code><nowiki>		importScript( 'User:DannyS712/Refund requester.js' ); // Backlink: [[User:DannyS712/Refund requester.js]] 		</nowiki></code> 
//
// If forking this script, please note my contributions / give me credit
//<nowiki>
$(function (){
var rf_config = {
	name: '[[User:DannyS712/Refund requester|Refund requester]]',
	version: 1.2,
	debug: false
};
var rf_summary = 'Request a refund with ' + rf_config.name + ' (version ' + rf_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' );
    	UND_init();
	}
} );
function request_refund( 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, rf_summary, false );
}
function make_request() {
	var page = ["placeholder"], type = ["placeholder"], reason = ["placeholder"];
	$('.UND-page').each(function () {page.push(this.value);});
	$('.UND-type').each(function () {type.push(this.value);});
	$('.UND-reason').each(function () {reason.push(this.value);});
	page = page[1];
	type = type[1];
	reason = reason[1];
	
	if (rf_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 + " }}";
	$("#UND-interface-content").css({
      "min-height": "7em",
      "width" : "875px",
      "height" : "200px",
    });
	$("#UND-interface-content").empty();
	$("#UND-interface-header").empty();
	$("#UND-interface-header").text("Request undeletion");
	$('.UND-tip').remove();
	$("#UND-interface-content").append(
		$('<button>').attr('id','UND-submit').text('Submit request'),
		$('<label>').attr('id','UND-submit').text(''),
		$('<textarea>').css({'resize':'none'}).attr({'id':'UND-output','readonly':'true','rows':'5','cols':'25'}).text(output)
	);
	$("#UND-interface-footer").append( $('<button>').attr('id', 'UND-back').css('margin-left','1em').text('Back') );
	$('#UND-submit').click(function() {
		var request = "\n\n" + output;
        $('#UND-back').remove();
        $('#UND-interface-content').empty();
        $('#UND-interface-content').append( $('<label>').attr('id','UND-submitting').text('\nSubmitting...') );
		if (rf_config.debug) console.log ( request );
		request_refund ( request );
	});
	$('#UND-back').click(function () {
        $('#UND-back').remove();
        $("#UND-interface-content").css({
    		"min-height": "7em",
		    "width" : "875px",
		    "height" : "200px",
	    });
        screen1();
    });
}
function screen1() {
	$("#UND-interface-header, #UND-interface-content, #UND-interface-footer").empty();
	$("#UND-interface-header").text("Request undeletion*");
	$("#UND-interface-footer").append($('<button>').attr('id', 'UND-cancel').text('Close'));
	$('#UND-cancel').click(function() {$('#UND-modal').remove();});
	$("#UND-interface-footer").prepend(
		$('<small>').attr('class','UND-tip').text('*For more information, see ').append($('<a>').attr('href','//en.wikipedia.org/wiki/WP:CSDRFU').text('undeleting speedily-deleted pages')),
		$('<br>').attr('class','UND-tip'),
		$('<small>').attr('class','UND-tip').text('**Leave blank if you are requesting a G13 undeletion'),
		$('<br>').attr('class','UND-tip')
	);
	$("#UND-interface-content").append(
		$('<div>').css('margin-bottom','0.5em').append(
			$('<label>').text('Page: '),
			$('<input>').attr({'type':'text','class':'UND-page'})
    	),
    	$('<div>').css('margin-bottom','0.5em').append(
	        $('<label>').text( 'Refund type: '),
	        $('<select>').attr('class','UND-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':'UND-reason'})
    	)
    );
    $("#UND-interface-content").append($('<button>').attr('id','UND-request').text('Preview request'));
    $('#UND-request').click(function() {make_request()});
}
function UND_init() {
  mw.util.addPortletLink('p-cactions', 'javascript:void(0)', 'Undelete', 'aca-UND', 'Easily request undeletion', null);
  $('#aca-UND').on('click', function() {
    $('body').prepend('<div id="UND-modal">'+
      '<div id="UND-interface">'+
        '<h4 id="UND-interface-header"></h4>'+
        '<hr>'+
        '<div id="UND-interface-content"></div>'+
        '<hr>'+
        '<div id="UND-interface-footer"></div>'+
      '</div>'+
    '</div>');
    $("#UND-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)"
    });
    $("#UND-interface").css({
      "background-color": "#e8f0ff",
      "margin": "15% auto",
      "padding": "2px 20px",
      "border": "1px solid #888",
      "width": "80%",
      "max-width": "60em",
    });
    $("#UND-interface-content").css({
      "min-height": "7em",
      "width" : "875px",
      "height" : "200px",
    });
    $("#UND-interface-footor").css("min-height", "3em");
    screen1();
  });
}
});
//</nowiki>