MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

/* Common routines */ function commafy( num ) { /* from stackoverflow */ /* trying to catch an error in Chrome about num being undefined */ if (typeof num == 'undefined') return null; var str = num.toString.split('.'); if (str[0].length >= 4) { str[0] = str[0].replace(/(\d)(?=(\d{3})+$)/g, '$1,'); }	if (str[1] && str[1].length >= 4) { str[1] = str[1].replace(/(\d{3})/g, '$1 '); }	return str.join('.'); }

/* UserTags configuration, see w:c:dev:UserTags * currently only testing this thing out, will add actual tags later once I learn more */ window.UserTagsJS = { modules: {}, tags: { // group: { associated tag data } //montheditor: { u:'Editor of the Month' }, // unused //featured: { u:'Featured' }, // unused //templates: { u:'Templates Guru' }, // unused //senioreditor: { u:'Senior Editor', title:'This person has made 500 or more edits on this wiki'} technician: { u:'Technician', title:'Maintainers of the back-end templates, javascript and stylesheets of this wiki' }	} }; UserTagsJS.modules.mwGroups = ['bureaucrat', 'sysop', 'rollback', 'moderator']; UserTagsJS.modules.custom = { 'Mfaizsyahmi': ['technician'], 'FegeleinParodies': ['technician'], 'Blakegripling ph': ['technician'] }; UserTagsJS.modules.inactive = 90; // 3 months /*UserTagsJS.modules.senioreditor = { namespace: 0, computation: function(edits) { return edits >= 500; } };*/

/* Import script pages */ importArticles({   type: "script",    articles: [        "w:c:dev:ShowHide/code.js",        "w:c:deadisland:User:Jgjake2/js/DISPLAYTITLE.js",        "MediaWiki:FloatingTableHeader.js",        "w:c:dev:Countdown/code.js",        "User:Mfaizsyahmi/object.js", /* Jodl Head */        'User:Mfaizsyahmi/UserTags/senioreditor.js', // for UserTags        'w:c:dev:UserTags/code.js',        "w:c:dev:Colors/code.js"    ] });

/* added condition so that section edits gets the proper edit summary */ /* 3 Aug '13 - replaced with less intrusive highlights on hovering publish button */ /* 17 Aug '13 - placeholder changes on hover (hope it'll me more persuasive :P ) */ /* 27 Jul '14 - default edit summary returns */ /* if ( $('textarea#wpSummary').val == '' ) { *   $('textarea#wpSummary').val('Can\'t be bothered with the edit summary');//.attr('readonly','readonly'); * } */ $('input[type="submit"]').mouseenter( function{	if ( $('textarea#wpSummary').val.length==0 ) {		$('textarea#wpSummary').css('border','2px dashed #ff0000').attr('placeholder','Bitte, add a summary of your edit. BITTE!')	} }).mouseleave( function{	$('textarea#wpSummary').css('border','1px solid #797979').attr('placeholder','Add a summary of your edit') }).click(function (e) {	if ( $('textarea#wpSummary').val.length==0 ) {		e.preventDefault;		$('textarea#wpSummary').val('Can\'t be bothered with the edit summary'); }});

// SocialBlade Widget (now supports multiple tags) $('.SocialBladeWidget').each(function {   var sbname=$(this).attr("data-name");    $(this).html(' ').show; });

/* * CODE FOR LIST OF UNTERGANGERS * NOW MOVED TO MediaWiki:UntergangerList.js * TO IMPROVE PERFORMANCE */ // since the verbatim proved to be useless, opted to use this instead // to load the script for the List of Untergangers page // // 13.9.12 Disabled for debugging - rows at bottom not being parsed correctly // 25.9.12 added button to load the script manually so that users can get back some functionality even as the script's being debugged // ==== // $(".page-List_of_Untergangers").append(' '); $('table.untergangers').after('Enable list enhancements '); function importUntergangerListScript { importScriptPage('MediaWiki:UntergangerList.js', 'hitlerparody'); $('button#ULscriptimport').remove; } // execute if not mfaizsyahmi logged in if ( $('#AccountNavigation a[href*="/User:Mfaizsyahmi"]').length == 0) importUntergangerListScript;

// I want to put stuff directly beneath the infobox! :@ // 6 Jan 13 - this seemed to be interfering with Infobox Extensions //$(".infobox").wrap(' '); //$(".underinfobox").appendTo(".infoboxcolumn");

// Marquee text, might come in handy for main page announcements //$('div.marquee').wrapInner(' ').show;

// *********** Grand Unified Downfall Scenes Database ************************** $(".scenes.list ol").find("ol, ul, dl").remove; $(".scenes.list+.alt-text").hide; $(".scenes.list").show;

function RepeatText(text, times) { return (new Array(times + 1)).join(text); }

if ( $("table.scenes").length && $("div.scenes.db").length ) {

$("div.scenes.db>ol").addClass("master"); $db = $("div.scenes.db").eq(0).clone; scenecount = $("ol.master>li", $db).length

$("table.scenes").each( function {       col = $("tr:first-child th", this).length;        rowstring = ' '+ RepeatText('  ',col) + ' ';        $(this).append( RepeatText(rowstring, scenecount) );

// applying header classes to cells, one column at a time for (j=1; j <= col; j++) { $( "td:nth-child(" +j+ ")", this).attr("class", $( "th:nth-child(" +j+ ")", this).attr("class") ); }       $(this).append( ' List retrieved from the Grand Unified Downfall Scenes Database.  ' ); });   $("ol.master>li", $db).each( function { idx = $(this).index+1; $desc = $("ul",this); // notes = $("dt",this).text; $link = $("dd a",this); id = $("ol>li", this); // haven't figured out how to use this $("ul, dl, ol", this).remove; scenename = $(this).html;

$row = $("table.scenes tr").eq(idx); $("td.index", $row).text(idx); $("td.name", $row).html(scenename); $("td.desc", $row).prepend($desc); // $("td.notes", $row).append(notes); $("td.links", $row).html( $link ); $("td.links a", $row).wrap(""); $("td.links", $row).wrapInner(""); }); } // ***************************************************************************

// NEWS (MAIN PAGE AND SELF PAGE) $(".scrollbox-news").after(' [Expand All] '); $('.page-Hitler_Parody_Wiki_News table.mw-collapsible th').prepend(' [All] ');

$(".newsExpander").click(function{   if ($(this).hasClass("newsExpander-collapsed")){        $(".scrollbox-news .mw-collapsible-toggle-collapsed, .page-Hitler_Parody_Wiki_News .mw-collapsible-toggle-collapsed").trigger("click");        $(".newsExpander").removeClass("newsExpander-collapsed").addClass("newsExpander-expanded");        if ($('.scrollbox-news').length ) $(this).text("[Collapse All]");    } else {        $(".scrollbox-news .mw-collapsible-toggle-expanded, .page-Hitler_Parody_Wiki_News .mw-collapsible-toggle-expanded").trigger("click");        $(".newsExpander").removeClass("newsExpander-expanded").addClass("newsExpander-collapsed");        if ($('.scrollbox-news').length ) $(this).text("[Expand All]");    } });

$(".scrollbox-news").prepend(' '); $(".scrollbox-news h3").append(' ↑top ');

/* Unterganger Infobox award headers show/hide toggle */ if ( $('.UntergangerInfobox .award').length >=3 ) { $('.UntergangerInfobox .award-header').append(' [Show] ') $('.award-toggle').click( function {       if ($(this).hasClass("award-toggle-collapsed")) {             $(".award").fadeOut;            $(this).removeClass("award-toggle-collapsed").text('[Show]')         } else {            $(".award").fadeIn;            $(this).addClass("award-toggle-collapsed").text('[Hide]')        }    }) $(".award").hide; }

/* ************ Template:Deadline ************* */ /* 1 Aug 13: turned into a named function so that it can be triggered anytime */

function deadlineFlags { var now = new Date; $('.contest-entry-stats').each( function {		var deadline = new Date( $(this).attr('data-date') );		//var deadline = new Date( '25 April 2013' );		if (deadline.getUTCHours+':'+deadline.getUTCMinutes+':'+deadline.getUTCSeconds == '0:0:0') { 			deadline.setUTCHours(23,59,59)		}		if ( now > deadline ) {			$(this).html(' ');		} else if ( (deadline-now)/(24*3600*1000) <= 3 ) { /* parseInt? */			$(this).html(' ');		} else {			$(this).html(' ');		}		//$(this).append(' '); }) } deadlineFlags;

/* ***** Downfall Scenes successor box ***** */ if ( $('.navbox.downfallscenes .scenes.list .selflink').length == 1 ) { $('.navbox.downfallscenes').before(' ') $('div.scenes-successor').load('/wiki/Template:Downfall_Scene_Successor?action=render table.scenes-successor', function{		var list = $('.navbox.downfallscenes .scenes.list ol')		var idx = $('.selflink', list).parent.index		$('table.scenes-successor .cur').html( $('li',list).eq(idx).clone.html )		if (idx > 0) $('table.scenes-successor .prev').html( $('li',list).eq(idx-1).clone.html )		if (idx < $('li',list).length ) $('table.scenes-successor .next').html( $('li',list).eq(idx+1).clone.html )	}); }

// Parody feed modifications - turn YT links into embedded players if( $('.page-Hitler_Parody_Wiki').length ) { console.log('page is Main Page, setting up timer for parody feed...') var parodyFeedChecker = setInterval( function{ checkParodyFeed }, 500); function checkParodyFeed{ if( $('.scrollbox#DPFparodies dl').length) { console.log('parody feed loaded!') clearInterval(parodyFeedChecker) $('.scrollbox#DPFparodies dl dd a[href*="//www.youtube.com/watch?"]').each(function{				var vidID = new RegExp("[\\?&]v=([^&#]*)").exec( $(this).attr('href') )				console.log(vidID)				$(this).hide.after(' ')			}); // $('.scrollbox#DPFparodies dl').after('complete!') }	} }

// moved here as this should be applied last... $('a.external').attr({ target: '_blank' });

/** Extra toolbar options ****************************************************** *  *  Description: Adds extra buttons to the old (non-enhanced) editing toolbar. *  *  Maintainers: User:MarkS, User:Voice of All, User:R. Koot */ mw.loader.using( 'mediawiki.action.edit', function {	var buttons, i, len;	buttons = ;	for ( i = 0, len = buttons.length; i < len; i++ ) {		mw.toolbar.addButton( buttons[i].imageFile, buttons[i].speedTip, buttons[i].tagOpen, buttons[i].tagClose, buttons[i].sampleText, buttons[i].id, buttons[i].id		);	} });

// SEASONAL BACKGROUND MUSIC //if ( $.cookie("HPW-nomusic") == null ) $(".WikiaArticle").append(' <iframe width="280" height="230" src="http://www.youtube.com/embed/6JMvYKrnseI?autoplay=1" frameborder="0"> ');

/* ************************ From the Jodl Files ************************* */ // something for rob and his hobo piret ;)

/* steamed fish ftw */ //$('a.external:not([href*="www.youtube.com/watch"])').click(function(e) { //   e.preventDefault //    window.location = 'http://www.wikihow.com/Cook-Steamed-Fish' //})

$('#closewindowbutton').on('click',function{$('.msgbox').fadeOut(150);});

/* MANUALLY switch off ads */ $('#removeads').on('click',function{     $('.WikiaTopAds').fadeOut(250);      $('.home-top-right-ads').fadeOut(250);      $('.wikia-ad').fadeOut(250);      $('.SelfServeUrl').fadeOut(250);      $('#WikiaArticleBottomAd').fadeOut(250);      $('.WikiaAdInContentPlaceHolder').fadeOut(250);      $('.WikiaAdInContent').fadeOut(250); });

/* Fetch YouTube channel information * Modified. Original version written by Fubuki風吹 *http://test-z.wikia.com/wiki/YouTube.js) */ $(function { if (!$('.youtube').length) return; $('.youtube').each(function {       var $this = $(this),            channel = $this.data('channel');        $.when( $.get('http://gdata.youtube.com/feeds/api/users/' + encodeURIComponent(channel) + '/uploads?alt=json'), $.get('http://gdata.youtube.com/feeds/api/users/' + encodeURIComponent(channel) + '?v=2&fields=yt:statistics,gd:feedLink&alt=json') ).then(function(a, b) { function formatNum(n) { // Original source: http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript return n.toString.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); }           $this .find('.subscribers').html(formatNum(b[0].entry.yt$statistics.subscriberCount)).end .find('.total-views').html(formatNum(b[0].entry.yt$statistics.totalUploadViews)).end; var subs = b[0].entry.yt$statistics.subscriberCount; if (subs>10000) { document.getElementById("subscribers").innerHTML = Math.floor(subs/1000) + "thousand"; } else if (subs>1000) { document.getElementById("subscribers").innerHTML = Math.floor(subs/100)*100; } else if (subs>100) { document.getElementById("subscribers").innerHTML = Math.floor(subs/10)*10; } else { document.getElementById("subscribers").innerHTML = subs; }               var views = b[0].entry.yt$statistics.totalUploadViews; if (views>10000000) { document.getElementById("total-views").innerHTML = Math.floor(views/1000000) + " million"; } else if (views>1000000) { document.getElementById("total-views").innerHTML = Math.floor(views/100000)/10 + " million"; } else if (views>100000) { document.getElementById("total-views").innerHTML = Math.floor(views/10000)*10 + " thousand"; } else if (views>10000) { document.getElementById("total-views").innerHTML = Math.floor(views/1000) + " thousand"; } else if (views>1000) { document.getElementById("total-views").innerHTML = Math.floor(views/100)*100; } else if (views>100) { document.getElementById("total-views").innerHTML = Math.floor(views/10)*10; } else { document.getElementById("total-views").innerHTML = views; }       });    }); });