User:Supdiop/sandbox.js

//from User:MusikAnimal/responseHelper.js //by MusikAnimal //

(function {	var responses = {}, inline = false, indentation = ":", templateName = "", defaultPrompt = "", anew = false, unresolved;	// base responses for permission pages	if(/Editing Wikipedia:Requests for permissions\/(?!Rollback|Confirmed).*\(section\)/.test(document.title)) {		indentation = "::";		templateName = "";		defaultPrompt = "Reason?";		responses = {			"Done" : {				code : "done",				summary : "done"			},			"Not done" : {				code : "not done",				summary : "Not done. ",				prompt : "Reason?"			},			"Comment" : {				code : "comment",				summary : "Comment. ",				prompt : "Comment:"			},			"Admin note" : {				code : "administrator note",				summary : "Admin note. ",				prompt : "Administrator note:"			}		};	} else if(document.title.indexOf("Editing Wikipedia:Requests for adminship/Ian.thomson (section)") !== -1) {		indentation = "::";		templateName = "subst:RFPR";		defaultPrompt = "Admin's name?"; responses = { "Support" : { code: "Support", summary : "support", prompt : "Why" },			"Oppose" : { code : "Oppose", summary : "oppose", prompt : "Why?" }		};	} else { mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Administrator intervention against vandalism', "WP:AIV"); mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Administrators%27 noticeboard/Edit warring', "WP:ANEW"); mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Requests for permissions', "WP:PERM"); mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Requests for page protection', "WP:RFPP"); mw.util.addPortletLink('p-navigation', mw.config.get( 'wgServer' ) + '/wiki/Wikipedia:Usernames for administrator attention', "WP:UAA"); }	var respondFn = function(e) { var response = e.data.response; var code = response.code, comment = "", value = ""; if(code.indexOf("|X") !== -1) { value = prompt((response.prompt ? response.prompt : defaultPrompt) + " (optional, hit OK to omit)"); if(value === null) return false; code = code.slice(0,(value.length ? -1 : -2)) + value; } else if(response.prompt) { value = prompt(response.prompt + " (optional, hit OK to omit)"); if(value === null) return false; if(value.length) comment = " "+value; }		var $textarea = $("#wpTextbox1"); var currentText = $textarea.val; var responseStr = "#" + "'"+"'"+"'"+code+"'"+"'"+"'"+" - "+comment+" ~"; if(inline) { var caretPos = $textarea[0].selectionStart; $textarea.val(currentText.substring(0, caretPos) + responseStr + currentText.substring(caretPos)); } else { $textarea.val(currentText + responseStr); }		if(anew && !unresolved) { var textArray = $textarea.val.split("\n"); $textarea.val(				textArray[0].replace('(Result: )','(Result: ' + (response.summary[0].toUpperCase + response.summary.slice(1) + value).trim + ')') +				'\n' + $textarea.val.split("\n").splice(1).join("\n")			); }		$("#wpSummary").val($("#wpSummary").val + (response.summary + value).trim); };	for(var response in responses) { var id = responses[response].id || responses[response].code.replace(/\W/g, ''); mw.util.addPortletLink('p-navigation', 'javascript:', "("+response+")", "rh-"+id, responses[response].summary); $("#rh-"+id).click({		 	response : responses[response]		}, respondFn); } }); //