User:Joshuagross/monobook.js/welcome-warn.js

/** * Library */

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

/**
 * URL encode / decode
 * http://www.webtoolkit.info/
 * http://www.webtoolkit.info/

var Url = {

// public method for url encoding encode : function (string) { // Escape single quote string = string.replace(/'/g, "&#39;"); return escape(this._utf8_encode(string)); },

// public method for url decoding decode : function (string) { return this._utf8_decode(unescape(string)); },

// private method for UTF-8 encoding _utf8_encode : function (string) { string = string.replace(/\r\n/g,"\n"); var utftext = "";

for (var n = 0; n < string.length; n++) {

var c = string.charCodeAt(n);

if (c < 128) { utftext += String.fromCharCode(c); }           else if((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); }           else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); }

}

return utftext; },

// private method for UTF-8 decoding _utf8_decode : function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0;

while ( i < utftext.length ) {

c = utftext.charCodeAt(i);

if (c < 128) { string += String.fromCharCode(c); i++; }           else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; }           else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; }

}

return string; }

} /** * Editing user talk - append message to textarea */ var months = ["January","February","March","April","May","June","July","August","September","October","November","December"]; function userTalkAppend (e) {	if (wgCanonicalNamespace == 'User_talk' && wgAction == 'edit') {		var editBox = document.getElementById('wpTextbox1'); var appendText = gup('text'); if (appendText) {			var curDate = new Date; editBox.value += (editBox.value ? "\n\n" : ""); editBox.value += ((gup('isWarning') == '1' ? '=='+months[curDate.getMonth]+' '+(curDate.getFullYear.toString)+'==' : '=='+Url.decode(gup('talkHeader'))+'==')); editBox.value += ("\n" + Url.decode(appendText)); editBox.scrollTop = editBox.scrollHeight; var prevPage = gup('prevPage'); document.getElementById('wpSummary').value = 'Replying to edit on '+prevPage+' - ' + Url.decode(gup('editSummary')); document.getElementById('wpSummary').value += " - aided by this script"; }	} }

/** * Automate use of templates when warning/welcoming users after recent edits */

var userTalk; var msgSignature = ' ~'+'~'+'~'+'~'; var tplStart = '{'+'{'; var tplEnd = '}'+'}';

function warnOrWelcome (e) {	var userTitle = 'Registered User'; // TODO var popup; if (document.getElementById('ww_div')) {		popup = document.getElementById('ww_div') }	else {		popup = document.createElement('div'); }	popup.id = 'ww_div'; popup.style.position = 'absolute'; popup.style.visibility = 'visible'; popup.style.zIndex = 10000; popup.style.backgroundColor = '#bebebe'; popup.style.border = '2px #555 solid'; popup.style.top = '200px'; popup.style.left = (parseInt(window.innerWidth)/2 - 200) + 'px'; popup.style.width = '400px'; popup.style.height = '400px'; document.body.appendChild(popup); var prevPg = Url.encode(wgPageName); popup.innerHTML = '' + ' '+userTitle+' (close) ' + " Welcome: Welcome anon user " + " Welcome: Good anon contribs - please register " + " Warning: Welcome anon vandal " + " Warning: Vandalism:" + "1 " + "2 " + "3 " + "4 " + " "		+ " Warning: <a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('warning - userpage vandalism')+"&text="+Url.encode(tplStart+'subst:uw-upv|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">Userpage vandalism</a> " + " Warning: <a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('warning - not using English')+"&text="+Url.encode(tplStart+'subst:uw-english|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">Not using English</a> " + " Warning: Spammy links:" + "<a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('warning - spammy links')+"&text="+Url.encode(tplStart+'subst:uw-spam1|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">1</a> " + "<a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('warning - spammy links')+"&text="+Url.encode(tplStart+'subst:uw-spam2|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">2</a> " + "<a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('warning - spammy links')+"&text="+Url.encode(tplStart+'subst:uw-spam3|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">3</a> " + "<a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('warning - spammy links')+"&text="+Url.encode(tplStart+'subst:uw-spam4|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">4</a> " + " "		+ " Warning: <a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('Please use the sandbox for testing edits - thank you!')+"&text="+Url.encode(tplStart+'subst:uw-selfrevert|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">Self-reverting test edits/vandalism</a> " + " Warning: NPOV:" + "<a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('warning - NPOV')+"&text="+Url.encode(tplStart+'subst:uw-npov1|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">1</a> " + "<a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('warning - NPOV')+"&text="+Url.encode(tplStart+'subst:uw-npov2|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">2</a> " + "<a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('warning - NPOV')+"&text="+Url.encode(tplStart+'subst:uw-npov3|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">3</a> " + "<a href=\"javascript:ww_loadframe('"+userTalk+"?action=edit&isWarning=1&talkHeader=&editSummary="+Url.encode('warning - NPOV')+"&text="+Url.encode(tplStart+'subst:uw-npov4|'+prevPg+'|'+msgSignature+tplEnd)+"&prevPage="+prevPg+"');\">4</a> " + " "		+ ""; }

function ww_loadframe (url) {	var popup = document.getElementById('ww_div'); popup.style.top = '0px'; popup.style.left = '0px'; popup.style.width = window.innerWidth + 'px'; popup.style.height = window.innerHeight + 'px'; popup.innerHTML = '<iframe src="'+url+'" width="100%" height="90%"> <a href="#" onclick="document.getElementById(\'ww_div\').style.visibility = \'hidden\';"> close </a> '; }

function warningWelcomingLoad (e) {	// Only operate on diff pages var diffNext = document.getElementById("differences-nextlink"); var diffPrev = document.getElementById("differences-prevlink"); if (diffNext || diffPrev) {		var nameLine = document.getElementById("mw-diff-ntitle2"); nameLine.innerHTML += '[<a href="#" id="warnWelcome"> Warn/Welcome</b></a>]'; document.getElementById('warnWelcome').addEventListener('click', warnOrWelcome, true); userTalk = "http://en.wikipedia.org/wiki/" + nameLine.innerHTML.match(/(User talk:[^"]+)/)[1];		userTalk = userTalk.replace(/ \(page does not exist\)/, '');	} }

addOnloadHook(function {   warningWelcomingLoad;   userTalkAppend; });

//				var win = new Window({className: "alphacube", title: "Sample", width:200, height:150, destroyOnClose: true, recenterAuto:false}); //				win.setLocation(100, 100); //				win.confirm('Allo', {okLabel:'Go', cancelLabel: 'Cancel'}); //				win.getContent.update("&lt;h1&gt;Hello world !!&lt;/h1&gt;"); //				win.showCenter;