User:Monchoman45/vector.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/************************************ vector stooff ************************************/
/* Note to self - a lot of this should be common.js w/ import to other relevant skin.js pages */

/* imports */
importScript('User:Monchoman45/common.js');
importScript('User:Monchoman45/toolbar.js');
/* cookie init */
function CheckCookie() {
	if(readCookie('globalJS') == null) {
		createCookie('globalJS', 'true', 99999);
	}
 
	$('#ca-watch, #ca-unwatch').before('<li><span><a onclick="ToggleGlobalJSCookie()" style="cursor:pointer; cursor:hand;"><img src="http://images3.wikia.nocookie.net/portalskin/images/2/20/Refresh_Icon.gif" style="margin-top:-3px;">&nbsp;<span id="GlobalJSText" style="background:none;">JS</span></a></span></li>');
}
 
$(CheckCookie);
 
function ToggleGlobalJSCookie() {
	if(readCookie('globalJS') == 'true') {
		createCookie('globalJS', 'false', 99999);
		document.getElementById('GlobalJSText').innerHTML = 'Off';
	}
	else {
		createCookie('globalJS', 'true', 99999);
		document.getElementById('GlobalJSText').innerHTML = 'On';
	}
	window.location.reload(true);
}

function UserLinks() { //The "My" really annoys me. Must kill it
	document.getElementById('pt-mytalk').getElementsByTagName('a')[0].innerHTML = 'Talk';
	document.getElementById('pt-preferences').getElementsByTagName('a')[0].innerHTML = 'Preferences';
	document.getElementById('pt-watchlist').getElementsByTagName('a')[0].innerHTML = 'Watchlist';
	document.getElementById('pt-mycontris').getElementsByTagName('a')[0].innerHTML = 'Contribs';
}
if(readCookie('globalJS') == 'true') {addOnloadHook(UserLinks);}

//ajax RecentChanges from dev.wikia
/*
 * ADVANCED AJAX AUTO-REFRESHING ARTICLES
 * Code courtesy of "pcj" of Wowpedia.
 * Modified to work in my interface and to my liking by Monchoman45
 */
if (!window.ajaxPages) {ajaxPages = ['Special:RecentChanges', 'Special:Watchlist', 'Special:Log'];}
var ajaxTimer;
var doRefresh = true;
function preloadAJAXRL() {
	if(readCookie('ajaxload-' + wgPageName) == null) {createCookie('ajaxload-' + wgPageName, 'on', 99999);}
	ajaxRLCookie = (readCookie('ajaxload-' + wgPageName) == 'on') ? true : false;
	$('#firstHeading').after('&nbsp;<span style="font-size: xx-small; line-height: 100%;" id="ajaxRefresh"><span id="ajaxToggleText">AJAX:</span><input type="checkbox" style="position:relative; top:2px;" id="ajaxToggle"><a onclick="loadPageData()" style="cursor:pointer; margin-top:1px;">Refresh now</a>&nbsp;&nbsp;<span style="display: none;" id="ajaxLoadProgress"><img src="http://images2.wikia.nocookie.net/dev/images/8/82/Facebook_throbber.gif" style="vertical-align: baseline;" border="0" alt="Refreshing page" /></span></span>');
	$('#ajaxLoadProgress').ajaxSend(function (event, xhr, settings){
		if (location.href == settings.url) {$(this).show();}
	}).ajaxComplete (function (event, xhr, settings) {
		if (location.href == settings.url) {$(this).hide();}
	});
	$('#ajaxToggle').click(toggleAjaxReload);
	$('#ajaxToggle').attr('checked', ajaxRLCookie);
	if (readCookie('ajaxload-' + wgPageName) == 'on') {loadPageData();}
}
function toggleAjaxReload() {
	if ($('#ajaxToggle').attr('checked') == true) {
		createCookie('ajaxload-' + wgPageName, 'on', 30);
		doRefresh = true;
		loadPageData();
	}
	else {
		createCookie('ajaxload-' + wgPageName, 'off', 30);
		doRefresh = false;
		clearTimeout(ajaxTimer);
	}
}
function loadPageData() {
	$('#bodyContent').load(location.href + ' #bodyContent > *', function (data) { 
		if (doRefresh) {ajaxTimer = setTimeout('loadPageData();', 60000);}
	});
}
if(readCookie('globalJS') == 'true') {addOnloadHook(function () { 
	for (i in ajaxPages) {
		if (wgPageName == ajaxPages[i] && $('#ajaxToggle').length == 0) {preloadAJAXRL();}
	}
});}