User:Quarenon/autocvu.js

/** * autocvu.js * * Modifies the CVU link when undoing an edit so that the cvuid template is automatically filled when opened. * * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */

addOnloadHook(function {	// http://www.netlobo.com/url_query_string_javascript.html	function getParam(name) {		name = name.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]');		var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); 		var results = regex.exec(window.location.href);		if (results == null) {			return '';		} else {			return decodeURIComponent(results[1]);		}	}

var cvuEditor = getParam('cvuEditor'); var cvuPage = getParam('cvuPage');

if (wgAction == 'edit' && getParam('undo')) { var undoEditor = document.getElementById('wpSummary').value.match(/s\/(.*?)\|/)[1];

var links = getElementsByClassName(document, 'a', 'mw-redirect'); for (i = 0; i < links.length; i++) { if (links[i].title == 'RS:CVU') { links[i].href = '/index.php?title=RuneScape:Counter_Vandalism_Unit&action=edit&section=7&cvuEditor=' + encodeURIComponent(undoEditor) + '&cvuPage=' + encodeURIComponent(wgPageName); links[i].style.backgroundColor = 'yellow'; links[i].title = 'CVU Quick-report available.'; break; }		}	} else if (wgAction == 'edit' && cvuEditor && cvuPage) { var lineSep = (navigator.appVersion.indexOf('MSIE') != -1) ? '\r\n' : '\n'; var obj = document.getElementById('wpTextbox1'); obj.value = obj.value.replace('-->' + lineSep, '-->\n\n{' + '{cvuid|' + cvuEditor + '|' + cvuPage + '}' + '}'); } });