User:DannyS712 test/refund.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:DannyS712 test/refund. |
//<nowiki>
$(function (){
var rf_config = {
name: '[[User:DannyS712/Refund requester|Refund requester]]',
version: 1.1,
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 = "\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-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 = 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>