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

/*** ACHIEVEMENTS QUICK-FORMATTING ***/ /*  Note: this script only works    */ /*        with achievements from    */ /*        xbox360achievements.org. */ /*************************************/

if (wgAction == 'edit') { addOnloadHook(addFormatAchievementsButton); };

function addFormatAchievementsButton { var image = document.createElement('img'); image.width = 23; image.height = 22; image.className = 'mw-toolbar-editbutton'; image.id = 'format-achievements-button'; image.src = 'http://media.strategywiki.org/images/b/b2/Achievement_unlocked.png'; image.border = 0; image.title = 'Format achievements'; image.style.cursor = 'pointer'; image.onclick = function { formatAchievements; return false; }; document.getElementById('toolbar').appendChild(image); return false; }

function formatAchievements { var txtarea = document.editform.wpTextbox1; if (txtarea.value != '') { var endPos; var endLine; var endLine2; var aName; var aDesc;

var startPos = txtarea.value.search(/\n	/g) + 2; while (startPos != 1) { endPos = txtarea.value.search(/[^\n]	/g) + 1 - startPos; aName = txtarea.value.substr(startPos, endPos).replace(/([\|\?#!%\.,=…:])/g,''); endLine = txtarea.value.substr(startPos + 2, txtarea.value.length).search(/\n/g) + startPos + 2; aDesc = txtarea.value.substr(endLine + 1, txtarea.value.substr(endLine + 1,txtarea.value.length).search(/\n/g)); txtarea.value = txtarea.value.substr(0, endLine).replace(/\n	/g, '\n| || ') + txtarea.value.substr(endLine, txtarea.value.length); txtarea.value = txtarea.value.substr(0, txtarea.value.search(/	/g)) + ' || ' + aDesc + ' || \n|-' + txtarea.value.substr(endLine2, txtarea.value.length); startPos = txtarea.value.search(/\n	/g) + 2; }; alert('Done.'); }; }

/*** END - ACHIEVEMENTS QUICK-FORMATTING ***/

/*** EDIT COUNTER ***/ var editPage = 'Edit count'; var tableClass = 'collapsible collapsed'; var tableFloat = ''; var tableStyle = ''; importScript('User:Najzere/edit_counter.js'); /*** END EDIT COUNTER ***/