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.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); }); }	};

this.patrol = function(e) { var a = e.target || e.srcElement; var next; var ajax = this.ajaxRequest; if(ajax) { ajax.onreadystatechange = function { if(ajax.readyState == 4) { if(AjaxPatrolAutoNext && (next = document.getElementById('differences-nextlink'))) { window.location = next.href; } else { document.getElementById('mw-diff-ntitle4').style.display="none"; }				}			};			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; }; };

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]'; } }