User:TheDefiant604/common.js

/************************************************/ /*                 Variables                   */ /************************************************/ var ajaxPages = ['Special:RecentChanges','Special:Watchlist']; //var ajaxSpecialPages = ['Recentchanges','Watchlist','Contributions']; var ajaxRefresh = 120000; // 2 mins var ajaxIndicator = '//slot1.images.wikia.nocookie.net/__cb1468579810/common/skins/common/images/ajax.gif'; var AjaxRCRefreshText = 'Auto-refresh'; var AjaxRCRefreshHoverText = 'Automatically refresh '+mw.config.get("wgPageName")+' every '+Math.floor(ajaxRefresh/1000)+' seconds'; /************************************************/ /************************************************/ /*                Code Import                  */ /************************************************/ // Documentation: http://dev.wikia.com/wiki/AjaxRC //importScriptURI('http://dev.wikia.com/wiki/MediaWiki:AjaxRC/code.js?action=raw&ctype=text/javascript');

/************************************************/ /*                   Code                      */ /************************************************/ /* * AjaxRC - Recent Changes auto-refresh * Originally by Pcj of Wowpedia (https://wow.gamepedia.com/User:Pcj) * Source1: https://wow.gamepedia.com/User:Pcj/ajaxrc.js * Source2: https://wow.gamepedia.com/MediaWiki:Common.js * Source3: http://dev.wikia.com/wiki/MediaWiki:AjaxRC/code.js */ var ajaxTimer; var doRefresh = true; var PageName = mw.config.get("wgPageName");

function setCookie(c_name,value,expiredays) { var exdate=new Date exdate.setDate(exdate.getDate+expiredays) document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString) }

function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "=") if (c_start!=-1) { c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) }	}	return "" }

function preloadAJAXRL { ajaxRLCookie = (getCookie("ajaxload-"+PageName)=="on") ? true:false; $(".firstHeading").append(' '+AjaxRCRefreshText+':   '); $("#ajaxLoadProgress").bind("ajaxSend", function {		$(this).show;	}).bind("ajaxComplete", function {		$(this).hide;	}); $("#ajaxToggle").click(toggleAjaxReload); $("#ajaxToggle").attr("checked", ajaxRLCookie); if (getCookie("ajaxload-"+PageName)=="on") loadPageData; }

function toggleAjaxReload { if ($("#ajaxToggle").is(":checked")) { setCookie("ajaxload-"+PageName, "on", 30); doRefresh = true; loadPageData; } else { setCookie("ajaxload-"+PageName, "off", 30); doRefresh = false; clearTimeout(ajaxTimer); } }

function loadPageData { $("#bodyContent").load(location.href + " #bodyContent > *", function (data) {		//$("ul.special>li:has(a[href*='Special:Log/useravatar'])").hide;		handleAutocollapse($("#bodyContent"));		$("#bodyContent .mw-collapsible").makeCollapsible;		if (doRefresh) ajaxTimer = setTimeout("loadPageData;", ajaxRefresh);	}); }

function handleAutocollapse(root) { var $ct = root.find(".mw-collapsible"); var $es = $ct.filter(".mw-autocollapse").not($ct.first).not(".mw-collapsed, .mw-uncollapsed, .mw-expanded"); $es.filter(function {		var link = $(this).find(".mw-collapsible-toggle a");		if (link.length) link.first.click;		return !link.length;	}).toggleClass("mw-collapsed mw-autocollapse"); }

$(function { 	if (ajaxPages.indexOf(PageName)!=-1) preloadAJAXRL; });