MediaWiki:Common.js

/*************************************************************************************************/ /*************************************************************************************************/ /**                                                                                            **/ /**  Any JavaScript here will be loaded for all users on every page load. **/ /** A lot of this code has been taken from other Wikis, which follow the same copyright laws. **/ /**                                                                                            **/ /*************************************************************************************************/ /*************************************************************************************************/

// RevealAnonIP settings -- MUST be before the script is imported window.RevealAnonIP = { permissions : ["rollback", "sysop", "bureaucrat"] };

/*********************************/ /* Beginning of Script importing */ /*********************************/

importArticles({   type: "script",    articles: [        "w:c:dev:AjaxRC/code.js",             // Ajax Recent Changes        "w:c:dev:ShowHide/code.js",           // Show - Hide button        "w:c:dev:DisplayClock/code.js",       // Clock        "w:c:dev:SignatureCheck/code.js",     // Checks for signature on talk pages        "w:c:dev:RevealAnonIP/code.js",       // Reveals Anonomous Users IP        "MediaWiki:StandardEditSummaries.js", // Standard Edit Summaries        "MediaWiki:UserRightsTitles.js"       // User Rights Titles    ] });

/***************************/ /* End of Script importing */ /***************************/

// AjaxRC settings ajaxPages = [ "Special:RecentChanges", "Special:Watchlist", "Special:Log", "Special:Contributions" ];

// Display clock settings // Display 12 hour time followed by day, month (English, full name) and year with "(UTC)" at the end window.DisplayClockJS = { format: "%2I:%2M:%2S %p %2d %B %Y (UTC)", location: "header" };

// Signature Check settings

window.SignatureCheckJS = { // Parts of the confirm prompt preamble: "There are a few potential problems with your edit:\n\n", // noSignature: "It looks like you forgot to sign your reply.\n", epilogue: "\nAre you sure you want to post this anyway?\n[This will violate wiki policy if you do not sign your signaure.]" };

/* This script is from Wiki Developers Wiki. For author attribution, please see http://dev.wikia.com/wiki/SignatureCheck/code.js?action=history */

/* Test if an element has a certain class * Description: Uses regular expressions and caching for better performance. * Maintainers: User:Mike Dillon, User:R. Koot, User:SG */

var hasClass = (function {    var reCache = {};    return function (element, className) {        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);   }; });

// // Patching in changes to table sorting and alt rows // Courtesy of Pcj from WoWPedia.org // function changeTS { window['ts_alternate'] = function (table) { var tableBodies = table.getElementsByTagName("tbody"); for (var i = 0; i < tableBodies.length; i++) {var tableRows = tableBodies[i].getElementsByTagName("tr"); for (var j = 0; j < tableRows.length; j++) { var oldClasses = tableRows[j].className.split(" "); var newClassName = ""; for (var k = 0; k < oldClasses.length; k++) { if (oldClasses[k] != "" && oldClasses[k] != "alt") newClassName += oldClasses[k] + " "; } tableRows[j].className = newClassName + (j%2 == 0?"alt":""); }   }  } } addOnloadHook(changeTS);

// // Settings for ShowHide function //

var ShowHideConfig = { brackets: '[]', autoCollapse: 3, };

/** The code marked below was taken from * http://mel-green.com/2009/02/javascript-1337-speak-translator/ * with a few minor translation improvements and tweaks to fit * the wiki framework. */

var PhrasesEnglish = new Array('the', 'dude', 'hacker',                 'hacks', 'you', 'cool', 'oh my gosh',                  'fear', 'power', 'own',                  'what the heck', 'elite', 'for the win',                   'loser', 'good game', 'sucks',                  'sucker', 'is', 'rocks', 'winner'); var PhrasesLeet = new Array('teh', 'dood', 'haxxor', 'hax', 'u',                 '1337', 'zomg', 'ph43', 'powwah', 'pwn',                   'wth', 'leet', 'ftw', 'n00b', 'gg',                  'sux', 'suxxor', 'iz', 'rox', 'pwnster');

var LettersEnglish = new Array('n', 'b', 'k', 'd', 'e', 'f', 'g', 'h',                 'p', 'm', 'r', 'l', 'o', 'q', 's', 't',                  'u', 'x', 'w', 'y', 'z', 'c', 'a', 'j',                   'i', 'v', ' '); var LettersLeet = new Array('/\\/', '|3', '|<', '[)', '3', '|=', '6', '|-|', '|*', '|\\/|', '|2', '|_', '0', '0.', '5', '+',                 '|_|', '><', '\\/\\/', '\'/', '2', '(', '/\\', '_|',                   '1', '\\/', '  ');

function translateText(inputString) {

for (i = 0; i < PhrasesEnglish.length; ++i) inputString = inputString.replace(                       new RegExp(PhrasesEnglish[i], "gi"),                        PhrasesLeet[i]                        ); for (i = 0; i < LettersEnglish.length; ++i) inputString = inputString.replace(                       new RegExp(LettersEnglish[i], "gi"),                        LettersLeet[i]                        ); return inputString; }

/* End of copied code, http://mel-green.com/2009/02/javascript-1337-speak-translator */

function LeetTrigger { $(".leet").each(function {     var originalText = $(this).html;     $(this).html(translateText(originalText));   }); } addOnloadHook(LeetTrigger);

/** Username replace function (Template:USERNAME) ******************************* * Inserts user name into * Originally by User:Splarka * New version by User:Spang */ function UserNameReplace { if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || wgUserName == null) return; var n = YAHOO.util.Dom.getElementsByClassName('insertusername', 'span', document.getElementById('bodyContent')); for ( var x in n ) { n[x].innerHTML = wgUserName; } } addOnloadHook(UserNameReplace);

// ***************************************************** // * 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 = ''; } else { var tpm = ''; }

// 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);

// ************************************************** // - end -  Experimental javascript countdown timer // **************************************************

/*** IRC thing ***/ $(function {	var nick = (wgUserName == null) ? ('FVW-Visitor-' + Math.floor(Math.random * 10)) : wgUserName.replace(/ /g, '_'); 	$('#IRCReplace').html(' '); });

/*** Facebook Box ***/ //thanks Ciencia function fBox { $('#redwallfbox').append(''); } $(fBox);

function fBoxx { $('#redwallfboxx').append(''); } $(fBox);