User:Greenpickle/monobook.js

window.WikEdDiffInit = function {

if (typeof(wikEdDiffScriptSrc) == 'undefined') { window.wikEdDiffScriptSrc = 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/diff.js&action=raw&ctype=text/javascript'; }

if (typeof(wikEdAllowLocalAjax) == 'undefined') { window.wikEdAllowLocalAjax = false; }

if (typeof(wikEdDiffCSS) == 'undefined') { window.wikEdDiffCSS = []; } WikEdDiffInitObject(wikEdDiffCSS, {		'.wikEdDiffWrapper':      'margin: 0 0 1em 0;',		'.wikEdDiffButtonWrapper': 'text-align: center;',		'.wikEdDiffButton':        'padding: 0; margin: 0.2em 0 0.33em 0;',		'.wikEdDiffDiv':           'background: #faf8f6; padding: 0.5em; border: 1px solid; border-color: #808080;'	});

if (typeof(wikEdUseLocalImages) == 'undefined') { window.wikEdUseLocalImages = false; }

if (typeof(wikEdImagePathLocal) == 'undefined') { window.wikEdImagePathLocal = 'file:///D:/wikEd/images/'; }

if (typeof(wikEdImagePath) == 'undefined') { window.wikEdImagePath = 'http://upload.wikimedia.org/wikipedia/commons/'; }

if (typeof(wikEdImage) == 'undefined') { window.wikEdImage = []; } WikEdDiffInitImage(wikEdImage, {		'wikEdDiff': 'c/c6/WikEdDiff.png'	});

if (typeof(wikEdText) == 'undefined') { window.wikEdText = []; } WikEdDiffInitObject(wikEdText, {		'wikEdDiffButtonImg alt': 'wikEdDiff',		'wikEdDiffButton title': 'Show improved diff view',		'wikEdDiffLoading':       '...'	});

if (typeof(wikEdFullDiff) == 'undefined') { window.wikEdFullDiff = false; }

window.wikEdDiffDiv = null; window.wikEdDiffWrapper = null; window.wikEdDiffButtonWrapper = null; window.wikEdDiffButton = null; window.wikEdDiffGetGlobalNode = null;

if (typeof(wikEdExternalScripts) == 'undefined') { window.wikEdExternalScripts = null; } if (typeof(wikEdDiffPreset) == 'undefined') { window.wikEdDiffPreset = false; }

window.wikEdDiffWikiGlobals = [];

window.wikEdDiffTable = null; }

if (typeof(wikEdDiffStartup) == 'undefined') { window.wikEdDiffStartup = false; }

window.WikEdDiffStartup = function {

if (window.wikEdDiffStartup == true) { return; }	window.wikEdDiffStartup = true;

if (window.wikEdPageLoaded == true) { WikEdDiffSetup; }

else { if (window.attachEvent != null) { window.attachEvent('onload', WikEdDiffSetup); }		else { window.addEventListener('load', WikEdDiffSetup, false); }		return; } }

window.WikEdDiffSetup = function {

if (document.getElementById('wikEdDiffSetupFlag') != null) { return; }	var flag = document.createElement('span'); flag.id = 'wikEdDiffSetupFlag'; flag.style.display = 'none'; flag.style.visibility = 'hidden'; document.body.appendChild(flag);

WikEdDiffInit;

var table = document.getElementsByTagName('table'); for (var i = 0; i < table.length; i ++) { if (table[i].className == 'diff') { wikEdDiffTable = table[i]; }	}

if (wikEdDiffTable == null) { return; }

window.wikEdDiffGreasemonkey = false; if (typeof(GM_getValue) == 'function' ) { wikEdDiffGreasemonkey = true; }

var variable = ['wgServer', 'wgArticlePath', 'wgScriptPath', 'wgCurRevisionId']; for (var i = 0; i < variable.length; i ++) { wikEdDiffWikiGlobals[ variable[i] ] = WikEdDiffGetGlobal(variable[i]); }

if (wikEdExternalScripts == null) { wikEdExternalScripts = []; var pageScripts = document.getElementsByTagName('script'); for (var i = 0; i < pageScripts.length; i ++) { var scriptSrc = pageScripts[i].src; var nameMatch = scriptSrc.match(/\/([^\/]*?)($|\?)/); if (nameMatch != null) { var scriptName = nameMatch[1]; if (scriptName != '') {

if ( (scriptName == 'diff.js') && (scriptSrc != wikEdDiffScriptSrc) ) { continue; }					wikEdExternalScripts[scriptName] = true; }			}		}	}

var head = document.getElementsByTagName('head')[0]; if (wikEdExternalScripts['diff.js'] == null) { if (typeof(WDiffString) == 'undefined') { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = wikEdDiffScriptSrc; head.appendChild(script); }		wikEdExternalScripts['diff.js'] = true; }

var diffStyle = new WikEdDiffStyleSheet; var rules = ''; for (var ruleName in wikEdDiffCSS) { var ruleStyle = wikEdDiffCSS[ruleName]; diffStyle.addRule(ruleName, ruleStyle); }

wikEdDiffWrapper = document.createElement('div'); wikEdDiffWrapper.id = 'wikEdDiffWrapper'; wikEdDiffWrapper.className = 'wikEdDiffWrapper';

wikEdDiffButtonWrapper = document.createElement('div'); wikEdDiffButtonWrapper.id = 'wikEdDiffButtonWrapper'; wikEdDiffButtonWrapper.className = 'wikEdDiffButtonWrapper'; wikEdDiffWrapper.appendChild(wikEdDiffButtonWrapper);

wikEdDiffButton = document.createElement('button'); wikEdDiffButton.id = 'wikEdDiffButton'; wikEdDiffButton.title = wikEdText['wikEdDiffButton title']; wikEdDiffButton.className = 'wikEdDiffButton'; wikEdDiffButtonWrapper.appendChild(wikEdDiffButton);

var diffImg = document.createElement('img'); diffImg.id = 'wikEdDiffButtonImg'; diffImg.src = wikEdImage['wikEdDiff']; diffImg.title = wikEdText['wikEdDiffButton title']; diffImg.alt = wikEdText['wikEdDiffButtonImg alt']; wikEdDiffButton.appendChild(diffImg);

wikEdDiffDiv = document.createElement('div'); wikEdDiffDiv.id = 'wikEdDiffDiv'; wikEdDiffDiv.className = 'wikEdDiffDiv'; wikEdDiffDiv.style.display = 'none';

wikEdDiffWrapper.appendChild(wikEdDiffDiv); if (wikEdDiffTable.nextSibling != null) { wikEdDiffTable.parentNode.insertBefore(wikEdDiffWrapper, wikEdDiffTable.nextSibling); }	else { wikEdDiffTable.parentNode.appendChild(wikEdDiffWrapper); }

if (window.attachEvent != null) { wikEdDiffButton.attachEvent('onclick', WikEdDiff); }	else { wikEdDiffButton.addEventListener('click', WikEdDiff, true); }

var cells = wikEdDiffTable.getElementsByTagName('td'); for (var i = 0; i < cells.length; i ++) { if (cells[i].className.indexOf('title') < 0) { cells[i].innerHTML = WikEdDiffLinkify(cells[i].innerHTML); }	}

var setting = WikEdDiffGetPersistent('wikEdDiff'); if ( (setting == '') && (typeof(wikEdDiffPreset) == 'boolean') ) { setting = wikEdDiffPreset; }	else if (setting == '1') { setting = true; }	if (setting == true) { WikEdDiff; }

if (typeof(setupTooltips) == 'function') { setupTooltips(wikEdDiffTable); }

return; }

window.WikEdDiff = function {

if (wikEdDiffDiv == null) { return; }

if (typeof(WDiffString) == 'undefined') { return; }

wikEdDiffDiv.style.display = 'block';

if (wikEdDiffDiv.innerHTML.length > 0) { return; }

if (wikEdDiffTable == null) { return; }

wikEdDiffDiv.innerHTML = wikEdText['wikEdDiffLoading'];

var url; var server = WikEdDiffGetGlobal('wgServer'); var scriptPath = WikEdDiffGetGlobal('wgScriptPath'); scriptPath = scriptPath.replace(server, ''); if ( (server != ) && (scriptPath != ) ) { url = server + scriptPath.replace(/\$1/, '') + '/index.php'; }	else { url = window.location.protocol + '//' + window.location.hostname + '/' + window.location.pathname; }

var article; var pageName = WikEdDiffGetGlobal('wgPageName'); if (pageName != '') { article = pageName; }	else { var articleMatch = window.location.search.match(/(\?|&)title=([^&#]+)/); if(articleMatch != null) { article = articleMatch[2]; }	}	url += '?title=' + encodeURIComponent(article) + '&action=raw&maxage=0';

var tdArray = document.getElementsByTagName('TD'); var tdOld; var tdNew; for (var i = 0; i < tdArray.length; i ++) { if (tdArray[i].className == 'diff-otitle') { tdOld = tdArray[i]; }		else if (tdArray[i].className == 'diff-ntitle') { tdNew = tdArray[i]; break; }	}	if ( (tdOld == null) || (tdNew == null) ) { return; }

var oldVersion = null; var newVersion = null;

var oldUrl; var newUrl;

if (		(/(\?|&)action=submit\b/.test(window.location.search) == true) ||		(/(\?|&)undoafter=/.test(window.location.search) == true)	) { var textarea = document.getElementsByName('wpTextbox1'); if (textarea.length == 0) { return; }		newVersion = textarea[0].value; newVersion = newVersion.replace(/\s+$/g, ''); var curRevisionId = WikEdDiffGetGlobal('wgCurRevisionId'); if (curRevisionId != '') { oldUrl = url + '&oldid=' + curRevisionId; }		else { oldUrl = url; }

var section = document.getElementsByName('wpSection'); if (section != null) { if (section.length > 0) { if (section[0].value != '') { oldUrl += '&section=' + section[0].value; }			}		}	}

else {

var versionMatchOld = tdOld.innerHTML.match(/(\?|&amp;)oldid=(\d+)/); var versionMatchNew = tdNew.innerHTML.match(/(\?|&amp;)oldid=(\d+)/); if (versionMatchOld == null) { return; }		oldUrl = url + '&oldid=' + versionMatchOld[2]; if (versionMatchNew != null) { newUrl = url + '&oldid=' + versionMatchNew[2]; }		else { newUrl = url; }	}

WikEdDiffAjaxRequest('GET', oldUrl, null, null, null, null, function(ajax) {		oldVersion = ajax.responseText;		if (newVersion != null) {			WikEdDiffResponse(oldVersion, newVersion);		}		return;	});

if (newUrl != null) { WikEdDiffAjaxRequest('GET', newUrl, null, null, null, null, function(ajax) {			newVersion = ajax.responseText;			if (oldVersion != null) {				WikEdDiffResponse(oldVersion, newVersion);			}			return;		}); }

return; }

window.WikEdDiffResponse = function(oldVersion, newVersion) {

var diffText = WDiffString(oldVersion, newVersion); if (wikEdFullDiff != true) { diffText = WDiffShortenOutput(diffText); }	wikEdDiffDiv.innerHTML = diffText; wikEdDiffDiv.style.display = 'block';

return; }

window.WikEdDiffLinkify = function(html) {

html = html.replace(/((https?|ftp):(\/\/[^\[\]\{\}\(\)<>\s&=\?#%]+|<[^>]*>)+)/g, function (p, p1) {		p1 = p1.replace(/<[^>]*>/g, '');		var url = encodeURI(p1);		url = url.replace(/\"/g, '%22');		url = url.replace(/\'/g, '%27');		url = url.replace(/#/g, '%23');		var ti = p1.replace(/\"/g, '&quot;');		return('' + p + '');	});

if ((wikEdDiffWikiGlobals['wgServer'] != null) && (wikEdDiffWikiGlobals['wgArticlePath'] != null)) { html = html.replace(/((\[\[)([^\|\[\]\{\}\n]*)([^\]\n&=\?#%]*)(]\]))/g, function (p, p1, p2, p3) {			p3 = p3.replace(/<[^>]*>/g, );			var url = encodeURI(p3);			url = url.replace(/\"/g, '%22');			url = url.replace(/\'/g, '%27');			url = url.replace(/#/g, '%23');			url = wikEdDiffWikiGlobals['wgServer'] + wikEdDiffWikiGlobals['wgArticlePath'].replace(/\$1/, ) + url;			var ti = p3.replace(/\"/g, '&quot;');			return('' + p + '');		}); }

return(html); }

window.WikEdDiffInitObject = function(array, preset) {

for (var key in preset) { if (array[key] == null) { array[key] = preset[key]; }	}	return; }

window.WikEdDiffInitImage = function(array, preset) {

for (var key in preset) { if (array[key] == null) {

if (wikEdUseLocalImages == true) { array[key] = wikEdImagePathLocal + preset[key].replace(/^[0-9a-f]+\/[0-9a-f]+\//, ''); }

else { array[key] = wikEdImagePath + preset[key]; }		}	}	return; }

window.WikEdDiffStyleSheet = function(documentObject) {

this.styleElement = null; if (documentObject == null) { documentObject = document; }

if (documentObject.createStyleSheet) { this.styleElement = documentObject.createStyleSheet; }

else { this.styleElement = documentObject.createElement('style'); this.styleElement.from = 'text/css'; var insert = documentObject.getElementsByTagName('head')[0]; if (insert != null) { this.styleElement.appendChild(document.createTextNode('')); // Safari 3 fix insert.appendChild(this.styleElement); }	}

this.addRule = function(selector, declaration) { if (this.styleElement.addRule) { this.styleElement.addRule(selector, declaration); }

else { if (this.styleElement.sheet != null) { if (this.styleElement.sheet.insertRule != null) { this.styleElement.sheet.insertRule(selector + ' { ' + declaration + ' } ', 0); }			}		}	};

this.addRules = function(rules) { this.styleElement.innerHTML = rules; return; } }

window.WikEdDiffGetPersistent = function(name) {

var getStr = '';

if (wikEdDiffGreasemonkey == true) { getStr = GM_getValue(name, ''); }	else { getStr = WikEdDiffGetCookie(name); }	return(getStr); }

window.WikEdDiffGetCookie = function(cookieName) {

var cookie = ' ' + document.cookie; var search = ' ' + cookieName + '='; var cookieValue = ''; var offset = 0; var end = 0; offset = cookie.indexOf(search); if (offset != -1) { offset += search.length; end = cookie.indexOf(';', offset) if (end == -1) { end = cookie.length; }		cookieValue = cookie.substring(offset, end); cookieValue = cookieValue.replace(/\\+/g, ' '); cookieValue = decodeURIComponent(cookieValue); }	return(cookieValue); }

window.WikEdDiffAjaxRequest = function(requestMethod, requestUrl, headerName, headerValue, bodyData, overrideMimeType, responseHandler) {

var request;

if (wikEdDiffGreasemonkey == true) { var headerArray = { 'User-Agent': navigator.userAgent } if (headerName != null) { headerArray[headerName] = headerValue; }		request = new GM_xmlhttpRequest({			'method': requestMethod,			'url':     requestUrl,			'headers': headerArray,			'data':    bodyData,			'onreadystatechange':				function(ajax) {					if (ajax.readyState != 4) {						return;					}					responseHandler(ajax);					return;				}		}); }

else { if (wikEdAllowLocalAjax == true) { if (typeof(netscape) == 'object') { netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead'); }		}

try { request = new XMLHttpRequest; }		catch(err) { try { request = new ActiveXObject('Microsoft.XMLHTTP'); }

catch(err) { try { request = new ActiveXObject('Msxml2.XMLHTTP'); }				catch(err) { return; }			}		}		request.open(requestMethod, requestUrl, true); if (headerName != null) { request.setRequestHeader(headerName, headerValue); }		if ( (request.overrideMimeType != null) && (overrideMimeType != null) ) { request.overrideMimeType(overrideMimeType); }		request.send(bodyData); request.onreadystatechange = function { if (request.readyState != 4) { return; }			responseHandler(request); return; }	}	return; }

window.WikEdDiffGetOffsetTop = function(element) { var offset = 0; do { offset += element.offsetTop; } while ( (element = element.offsetParent) != null ); return(offset); }

window.WikEdDiffGetGlobal = function(globalName) {

var globalValue; if (wikEdDiffGreasemonkey == true) { if (wikEdDiffGetGlobalNode == null) { wikEdDiffGetGlobalNode = document.getElementById('wikEdDiffGetGlobalNode'); }		if (wikEdDiffGetGlobalNode == null) { wikEdDiffGetGlobalNode = document.createElement('textarea'); wikEdDiffGetGlobalNode.id = 'wikEdDiffGetGlobalNode'; wikEdDiffGetGlobalNode.style.display = 'none'; wikEdDiffGetGlobalNode.style.visibility = 'hidden'; document.body.appendChild(wikEdDiffGetGlobalNode); }		location.href = 'javascript:void(typeof(' + globalName + ')!=\'undefined\'?(' + globalName + '!=null?(document.getElementById(\'wikEdDiffGetGlobalNode\').value=' + globalName + '.toString):null):null)'; globalValue = wikEdDiffGetGlobalNode.value; }	else { try { globalValue = eval(globalName + '.toString;'); }		catch(err) { } }	return(globalValue); }

WikEdDiffStartup;