MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */   /* If you don't know what you are doing, do not edit this page */ /* */   // ***************    // Easy-remove CVU // ***************   // Courtesy of Megan window.onload = function { var cake = (unescape(wgPageQuery)); if (cake.indexOf("remove=") > 0) { var mhm = cake.substring(unescape(wgPageQuery).indexOf("remove=") + 7, cake.indexOf("&section=1")); var oldtext = document.getElementById('wpTextbox1').value; if (oldtext.indexOf("{{CVU|" + mhm) > 0) { var cake = oldtext.substring(oldtext.indexOf("{{CVU|" + mhm)); var cak3 = cake.substring(0, cake.indexOf("}}") + 2); document.getElementById('wpTextbox1').value = oldtext.replace(cak3, "{{CVU|Example}}"); document.editform.wpSave.click; }       }    }

// ************   // Easy-add CVU // ************   // Courtesy of Megan importScriptPage('User:Cakemix/QCVUAdder.js', 'callofduty');

// *********   // IRC Login Fixed by Megan (Now stops f***ing loading on every page) // *********   $(document).ready(function  {        if ($('#IRClogin')) {            var nick = (wgUserName == null) ? ('Wikian' + Math.floor(Math.random * 10)) : wgUserName.replace(/ /g, '_');            $('#IRClogin').html(' ');        }        if ($('#CVNIRClogin')) {            var nick = (wgUserName == null) ? ('Wikian' + Math.floor(Math.random * 10)) : wgUserName.replace(/ /g, '_');            $('#CVNIRClogin').html(' ');        }        if ($('#CoDferenceIRClogin')) {            var nick = (wgUserName == null) ? ('Wikian' + Math.floor(Math.random * 10)) : wgUserName.replace(/ /g, '_'); $('#CoDferenceIRClogin').html(' '); }   });

// *************************   // Template:Game positioning // *************************   // credit to Fallout wiki

function addTitleIcons { if (skin == 'monaco' || skin == 'monobook' || skin == 'oasis') { var insertTarget;

switch (skin) { case 'monobook': insertTarget = $('#firstHeading'); break; case 'monaco': insertTarget = $('#article > h1.firstHeading'); break; case 'oasis': if (wgAction != 'submit' && wgNamespaceNumber != 112) { insertTarget = $('#WikiaArticle'); }               break; }

if (insertTarget) { $('#gametemplate').css('display', 'block').prependTo(insertTarget); }       }    }

jQuery(function ($) {       addTitleIcons;    });

// *****************   // Collapsible stuff // *****************   /* */

var ShowHideConfig = { userLang: false, en: { show: "expand", hide: "hide", showAll: "expand all", hideAll: "hide all" }   };

importScriptPage('ShowHide/code.js', 'dev');

// *************************************************   // Experimental javascript countdown timer (Splarka) // Version 0.0.3 // *************************************************   //    // Usage example: //     //  Only January 01 2007 00:00:00 PST until New years. //     //  Javascript disabled.

function updatetimer(i) { var now = new Date; var then = timers[i].eventdate; var diff = count = Math.floor((then.getTime - now.getTime) / 1000);

// catch bad date strings if (isNaN(diff)) { timers[i].firstChild.nodeValue = '** ' + timers[i].eventdate + ' **'; return; }

// determine plus/minus if (diff < 0) { diff = -diff; var tpm = 'T plus '; } else { var tpm = 'T minus '; }

// calcuate the diff var left = (diff % 60) + ' seconds'; diff = Math.floor(diff / 60); if (diff > 0) left = (diff % 60) + ' minutes ' + left; diff = Math.floor(diff / 60); if (diff > 0) left = (diff % 24) + ' hours ' + left; diff = Math.floor(diff / 24); if (diff > 0) left = diff + ' days ' + left timers[i].firstChild.nodeValue = tpm + left;

// a setInterval is more efficient, but calling setTimeout // makes errors break the script rather than infinitely recurse timeouts[i] = setTimeout('updatetimer(' + i + ')', 1000); }

function checktimers { //hide 'nocountdown' and show 'countdown' var nocountdowns = getElementsByClassName(document, 'span', 'nocountdown'); for (var i in nocountdowns) nocountdowns[i].style.display = 'none' var countdowns = getElementsByClassName(document, 'span', 'countdown'); for (var i in countdowns) countdowns[i].style.display = 'inline'

//set up global objects timers and timeouts. timers = getElementsByClassName(document, 'span', 'countdowndate'); //global timeouts = new Array; // generic holder for the timeouts, global if (timers.length == 0) return; for (var i in timers) { timers[i].eventdate = new Date(timers[i].firstChild.nodeValue); updatetimer(i); //start it up       } }   addOnloadHook(checktimers);

// *************************************************   // Pagetitle rewrite //   // Rewrites the page's title, used by Template:Title // *************************************************   $(function  {        var newTitle = $("#title-meta").html;        if (!newTitle) return;        var edits = $("#user_masthead_since").text;        $(".firstHeading,#WikiaUserPagesHeader h1,#WikiaPageHeader h1").html(newTitle);        $(".#user_masthead_head h2").html(newTitle + "" + edits + " ");    });

/* */

// ****************   // Duplicate images // ****************   importScriptPage('DupImageList/code.js', 'dev');

// *********************************************************************   // Added SiteNotice Functionality, credit to RuneScape wiki for the code //   // Functions: //  * Moves the dismiss link into the SiteNotice table. //  * Saves the show/hide status of the SiteNotice in a cookie. //  * Automatically expands the SiteNotice when the ID is updated. // *********************************************************************   var dCookieName = "dismissSiteNotice="; var msgClose = "dismiss";

var hCookieName = "hideSiteNotice="; var hCookiePos = document.cookie.indexOf(hCookieName); var hCookieValue = "";

function editSiteNotice { var snbox = document.getElementById('mw-dismissable-notice');

if (snbox != null) { if (hCookiePos > -1) { hCookiePos = hCookiePos + hCookieName.length; var hideEndPos = document.cookie.indexOf(";", hCookiePos); if (hideEndPos > -1) { hCookieValue = document.cookie.substring(hCookiePos, hideEndPos); } else { hCookieValue = document.cookie.substring(hCookiePos); }           }

var newLink = document.createElement('a'); newLink.setAttribute('href', "javascript:dismissNotice;"); newLink.setAttribute('title', 'Dismiss this notice.'); newLink.innerHTML = msgClose;

var newSpan = document.createElement('span'); newSpan.id = 'siteNoticeDismiss'; newSpan.appendChild(document.createTextNode(' [')); newSpan.appendChild(newLink); newSpan.appendChild(document.createTextNode(']'));

var hideLink = document.getElementById("collapseButton" + "0"); hideLink.href = "javascript:hideSiteNotice;" hideLink.parentNode.style.width = "12em"; hideLink.parentNode.appendChild(newSpan);

if (hCookieValue != siteNoticeID && hideLink.innerHTML == "show") { collapseTable(0); }           if (hCookieValue == siteNoticeID && hideLink.innerHTML == "hide") { collapseTable(0); }       }    }

function hideSiteNotice { var hideLink = document.getElementById("collapseButton" + "0"); var date = new Date;

if (hideLink.innerHTML == 'hide') { date.setTime(date.getTime + 30 * 86400 * 1000); } else { date.setTime(date.getTime - 30 * 86400 * 1000); }       document.cookie = hCookieName + siteNoticeID + "; expires=" + date.toGMTString + "; path=/"; collapseTable(0); }

addOnloadHook(editSiteNotice);

// *****************************************************************************************   // Description: Redirects from /User:UserName/skin.js or .css to the user's actual skin page // Maintainer: Cacycle // *****************************************************************************************   if (wgArticleId == 0 && wgUserName) { var slash = wgPageName.indexOf('/'); var norm = wgPageName.substr(0, slash) + wgPageName.substr(slash).toLowerCase; var test = 'User:' + wgUserName.replace(/ /g, '_') + '/skin.'; var ext = null; if (norm == test + 'js') ext = 'js'; else if (norm == test + 'css') ext = 'css'; if (ext != null) window.location.href = window.location.href.replace(/\/skin.(css|js)/i, '/' + skin.replace('oasis', 'wikia') + '.' + ext); }   // ***************************************    // Ajax-refresh (code from pcj of WoWWiki) // ***************************************   var ajaxPages = ["Special:RecentChanges", "Special:Log", "Special:Contributions", "Special:AbuseLog"]; var AjaxRCRefreshText = 'Auto-Refresh'; importScriptPage('AjaxRC/code.js', 'dev');

// *********************************************   // Page background changer (courtesy of Megan) // *********************************************

function BgImage { if ($('#BgImage').text.length > 3 && ($('#BgImage').text.match("(((http://www)|(http://)|(www))[-a-zA-Z0-9@:%_\+.~#?&//=]+)\.(jpg|jpeg|gif|png|bmp|tiff|tga|svg)"))) { $('#BgImage').hide; $('body').css("background-image", "url(" + $('#BgImage').text + ") !important").css("backgroundPosition", "top center").css("backgroundRepeat", "no-repeat").css("background", "none");

}   }

$(document).ready(BgImage);

// ***************************************   // Auto hide // ***************************************

function addHideButtons { var hidables = getElementsByClass('hidable');

for (var i = 0; i < hidables.length; i++) { var box = hidables[i]; var button = getElementsByClass('hidable-button', box, 'span');

if (button != null && button.length > 0) { button = button[0];

button.onclick = toggleHidable; button.appendChild(document.createTextNode('[Hide]'));

if (new ClassTester('start-hidden').isMatch(box)) { button.onclick('bypass'); }           }        }    }

function toggleHidable { var parent = getParentByClass('hidable', this); var content = getElementsByClass('hidable-content', parent); var nowShown;

if (content != null && content.length > 0) { content = content[0];

if (content.style.display == 'none') { content.style.display = content.oldDisplayStyle; this.firstChild.nodeValue = '[Hide]'; nowShown = true; } else { content.oldDisplayStyle = content.style.display; content.style.display = 'none'; this.firstChild.nodeValue = '[Show]'; nowShown = false; }       }    }

function getElementsByClass(searchClass, node, tag) { var classElements = new Array;

if (node == null) { node = document; }

if (tag == null) { tag = '*'; }

var els = node.getElementsByTagName(tag); var elsLen = els.length; var tester = new ClassTester(searchClass);

for (i = 0, j = 0; i < elsLen; i++) { if (tester.isMatch(els[i])) { classElements[j] = els[i]; j++; }       }

return classElements; }

function getParentByClass(className, element) { var tester = new ClassTester(className); var node = element.parentNode;

while (node != null && node != document) { if (tester.isMatch(node)) { return node; }

node = node.parentNode; }

return null; }

function ClassTester(className) { this.regex = new RegExp("(^|\\s)" + className + "(\\s|$)"); }

ClassTester.prototype.isMatch = function (element) { return this.regex.test(element.className); }

addOnloadHook(addHideButtons)

//    ///////////////////////////////////////////////////////////////////////////////////////////////////////////    // FIND DUPLICATE IMAGES // Code courtesy of "pcj" of WoWWiki. ///////////////////////////////////////////////////////////////////////////////////////////////////////////   dil = new Array;

function findDupImages(gf) { output = ""; url = "/api.php?action=query&generator=allimages&prop=duplicatefiles&gailimit=500&format=json"; if (gf) url += "&gaifrom=" + gf; $.getJSON(url, function (data) {           if (data.query) {                pages = data.query.pages;                for (pageID in pages) {                    dils = "," + dil.join;                    if (dils.indexOf("," + pages[pageID].title) == -1 && pages[pageID].title.indexOf("File::") == -1 && pages[pageID].duplicatefiles) {                        output += " " + pages[pageID].title + " \n\n";                        for (x = 0; x < pages[pageID].duplicatefiles.length; x++) {                            output += "File:" + pages[pageID].duplicatefiles[x].name + "\n";                            dil.push("File:" + pages[pageID].duplicatefiles[x].name.replace(/_/g, " "));                        }                        output += "\n\n"                    } }               $("#mw-dupimages").append(output); if (data["query-continue"]) setTimeout("findDupImages('" + data["query-continue"].allimages.gaifrom + "');", 5000); }       });    }    $(function  { if ($("#mw-dupimages").length) findDupImages; });

// username replace, except for in user blogs

function UserNameReplace { if (typeof (disableUsernameReplace) != 'undefined' && disableUsernameReplace || wgUserName == null) return; if (wgCanonicalNamespace != "User_blog") { $("span.insertusername").html(wgUserName); }   }    addOnloadHook(UserNameReplace);

/* lock blog comments for blogs that haven't been commented on for more than 30 days. by: Joey Ahmadi

$(function {        if (wgNamespaceNumber == 500 && $('#article-comments-ul li').size > 1) {            var then = $('#article-comments-ul > .article-comments-li:first .permalink').attr('href');            then = new String(then.match(/\d{8}/));            var monthnames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];            var year = then.match(/^\d{4}/);            var month = then.substring(4, 6);            month--;            month = monthnames[month];            var day = then.match(/\d{2}$/);            then = new Date(month + '' + day + ', ' + year);            var old = parseInt(now - then);            old = Math.floor(old / (1000 * 60 * 60 * 24));            if (old > 30) {                $('#article-comm').attr('disabled', 'disabled').text('This blog post hasn\'t been commented on for over 30 days. There is no need to comment.');               $('#article-comm-submit').attr('disabled', 'disabled');                $('.article-comm-reply').remove;            }        }    });