User:Najzere/common.js

//Common library functions used by many of the scripts below importScript('User:Ryan Schmidt/Scripts/library.js');

//Find and replace script //by Zocky importScript('User:Ryan Schmidt/Scripts/SearchBox.js'); /** * AJAX patrol feature version 1.1 * by Ryan Schmidt < http://strategywiki.org/wiki/User:Ryan_Schmidt > */

/* * CONFIGURATION * You may set whether or not to automatically browse to the next diff * By placing the following BEFORE the importScript call: * var AjaxPatrolAutoNext = true; */

var AjaxPatrolAutoNext = true; AjaxPatrol = new function { this.interval = [null, 0];

this.setup = function { var links = getElementsByClassName(document, 'span', 'patrollink'); for(var i=0; i<links.length; i++) { addClickHandler(links[i].getElementsByTagName('a')[0], function(e) { AjaxPatrol.patrol(e); }); }		AjaxPatrol.firstHeading = document.getElementsByTagName('h1')[0]; };

this.patrol = function(e) { var a = e.target || e.srcElement; var next; var ajax = this.ajaxRequest; if(ajax) { this.dotmessage('Patrolling edit, please wait'); var origt = document.title; document.title = '(' + origt + ')'; ajax.onreadystatechange = function { if(ajax.readyState == 4) { clearInterval(AjaxPatrol.interval[0]); if(AjaxPatrolAutoNext && (next = document.getElementById('differences-nextlink'))) { AjaxPatrol.dotmessage('Done. Loading next diff'); clearInterval(this.interval); window.location = next.href; } else { AjaxPatrol.message('Done. You may now browse away from the page.'); document.title = origt; }				}			};			ajax.open('GET', a.href, true); ajax.send(null); e.preventDefault; }	};

this.ajaxRequest = function { var ret = false; try { ret = new XMLHttpRequest; } catch(e) { try { ret = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { ret = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { return false; }			}		}		return ret; };

this.dotmessage = function(msg) { this.interval[1]++; if(this.interval[1] > 3) this.interval[1] = 0; var extra = ''; for(var i=0; i<this.interval[1]; i++) { extra += '.'; }		this.interval[0] = setInterval('AjaxPatrol.dotmessage("'+msg+'")', 500); this.message(msg + extra); }

this.message = function(msg) { var div; if(!(div = document.getElementById('ajaxpatrol-box'))) { div = document.createElement('div'); div.className = 'header_box'; div.id = 'ajaxpatrol-box'; div.innerHTML = ' ' + msg + ' '; this.firstHeading.parentNode.insertBefore(div, this.firstHeading); } else { div.innerHTML = ' ' + msg + ' '; }	}; };

addOnloadHook(function {	if(typeof AjaxPatrolAutoNext == 'undefined') {		AjaxPatrolAutoNext = false;	}	AjaxPatrol.setup; });

/* Adding cleanup button */ addOnloadHook( function {  addPersonalItem('cleanup', '/wiki/StrategyWiki:Cleanup project/Daily tasks', 'Cleanup', 'preferences'); });

/* Add source URL to summary when uploading from URL */ if (wgPageName == "Special:Upload") { addOnloadHook(get_URL); }

function get_URL { var URL_form=document.getElementById('wpUploadFileURL'); addHandler(URL_form, 'change', insert_URL); }

function insert_URL(event) { var URL = document.getElementById('wpUploadFileURL').value; var summary = document.getElementById('wpUploadDescription'); var re = /\[http.*? Source URL\]/; if(summary.value.match(re)) { summary.value = summary.value.replace(re, '[' + URL + ' Source URL]'); } else { summary.value = summary.value + '\n\n[' + URL + ' Source URL]'; } }