MediaWiki:Common.js

/******************************************************************************/ /*            SCRIPTS EXECUTED AFTER THE HTML DOCUMENT IS LOADED             */ /******************************************************************************/

$(function {

"use strict";

////////////////////////////////////////////////////////////////////////////   //                                GENERAL                                 // ////////////////////////////////////////////////////////////////////////////

/*******************/   /* Spoiler overlay */ /*******************/

// This script must always be the very first executed

var lastVisit = window.localStorage.getItem('spoilerCache'); // Gets the timestamp of the last visit stored in the cache var thisVisit = Date.now; // Returns the current time in milliseconds var howLong = thisVisit - lastVisit; // Checks how much time has passed since the last visit if (howLong < 2592000000) { // If it's been less than one month since the last visit $('#spoiler-overlay').remove; // Removes the alert }   $('#show-spoilers').click(function  { // When clicking the button to remove spoilers    $('#spoiler-overlay').remove; // Removes the alert        localStorage.setItem("spoilerCache", thisVisit); // Saves the timestamp of this visit    });

// Adds button to rehide spoilers to the row of buttons if ($.inArray("Spoilers", mw.config.get('wgCategories')) > -1) { $('#WikiaPageHeader').append('Rehide spoilers'); $('#reset-spoilers').click(function {            localStorage.removeItem('spoilerCache');            location.reload;        }); }

/********************************************/   /* Inserts links to blogs in navigation bar */ /********************************************/

$('.subnav-2').first.append('Blogs');

/********************************/   /* Tooltips for the media icons */ /********************************/

$("#media-icons a").tooltip;

////////////////////////////////////////////////////////////////////////////   //                               HOMEPAGE                                 // ////////////////////////////////////////////////////////////////////////////

if (mw.config.get('wgIsMainPage') === true) {

/*******************************/       /* Random Episode and Calendar */ /*******************************/

var parse = function (page, div) { $.ajax({               dataType: 'text',                data: {                    action: 'parse',                    format: 'xml',                    disablepp: '1',                    prop: 'text',                    text: page                    },                url: '/api.php',                success: function (data) {                    $(div).html($('text', $(data)[1]).text);                }            }); };       var values = [ ['', 'div#RandomEpisode'], ['', 'div#Calendar'] ];       values.forEach(function (args) {            parse.apply(null, args);        });

/**************************/       /* Homepage Social Module */ /**************************/

var homeSocial = ' ';

$('div#social-module').html(homeSocial);

}

});

/******************************************************************************/ /*  SCRIPTS EXECUTED AFTER THE WHOLE PAGE AND ALL OBJECTS HAVE BEEN LOADED   */ /******************************************************************************/

$(window).load(function {

'use strict';

/************************************/   /* Social module and Discord banner */ /************************************/

// Module var socialDiscord = '' + '' + '' +       '' + ' ' +   '' + ' Follow us! ' +       ' ' +    ' ';

// Variables var namespaces = [ 2, // User profiles 1200 // Message Walls ];   var pagenames = ['Special:WikiActivity', 'Special:Following']; var pathname = window.location.pathname.split('/'); // Returns /wiki/rest/of/path and splits it in "/" to work with them below

// Inserts the module if (mw.config.get('wgIsMainpage') !== true) { // Checks if it's not the homepage

// Inserts module above Recent Wiki Activity in most pages $('#WikiaRecentActivity').before(socialDiscord);

// Inserts it in different places in forum and blogs if (mw.config.get('wgPageName') !== 'Special:WikiActivity') { //Checks if it's not Wiki Activity if (mw.config.get('wgUserGroups').indexOf('user') > -1) { // If it's a registered user if ($('.ForumActivityModule').length) { // Checks if it's the forum $('.ChatModule').before(socialDiscord); // Inserts module above Chat }           } else { // If it's an anonymous user $('.ForumActivityModule').first.before(socialDiscord); // Inserts module above either Forum Activity or Related Threads $('.WikiaBlogListingBox').before(socialDiscord); // Inserts module above Popular blog posts }       }

// Inserts it above Chat in other pages if ((namespaces.indexOf(mw.config.get('wgNamespaceNumber')) > -1 && pathname[3] === 'undefined') || pagenames.indexOf(mw.config.get('wgPageName')) > -1 || pathname[2] === 'Special:Contributions') { // If it's Message Walls, WikiActivity, Following or Contributions $('.ChatModule').before(socialDiscord); // Inserts module above Chat }

}

/*********************************************/   /* Moves Community, Trending Fandom Articles */ /* Insights and HotSpots below Chat         */ /*********************************************/

$('.ChatModule').after($('.community-page-entry-point-module, #RECIRCULATION_RAIL, .insights-module, .HotSpotsModule'));

/************************************************/   /* Adds option to refresh page to edit dropdown */ /************************************************/

var url = '//' + location.host + location.pathname + '?action=purge'; $('.WikiaMenuElement').append('Refresh');

});

/******************************************************************************/ /*                             IMPORTED SCRIPTS                              */ /******************************************************************************/

//////////////////////////////////////////////////////////////////////////////// //                             CONFIGURATIONS                                // ////////////////////////////////////////////////////////////////////////////////

/*************/ /* User Tags */ /*************/

// Core configuration window.UserTagsJS = { modules: {}, tags: { bureaucrat: { u: 'Bureaucrat', link: 'Project:Administrators', order: -7 },       sysop: { u: 'Administrator', link: 'Project:Administrators', order: -6 },       threadmoderator: { link: 'Project:Discussions Moderators', order: -5 },       'content-moderator': { u: 'Content Moderator', link: 'Project:Content Moderators', order: -4 },       chatmoderator: { link:'Project:Chat Moderators', order: -3 },       rollback: { u: 'Rollbacker', link: 'Project:Rollbackers', order: -2 },       reporter: { u: 'Reporter', link: 'Project:Reporters', order: -1 },       bot: { u: 'Bot', link: 'Project:Bots' }

} };

// Adds users' MediaWiki groups to the internal group list UserTagsJS.modules.mwGroups = [ 'bureaucrat', 'sysop', 'threadmoderator', 'content-moderator', 'chatmoderator', 'rollback', 'bot' ];

// Custom ranks UserTagsJS.modules.custom = { 'Sim0n2170': ['reporter'], 'Manuel de la Fuente': ['reporter'], 'JinxTheFunhouse': ['reporter'] };

// Removes certain groups UserTagsJS.modules.metafilter = { 'sysop': ['bot'] // Removes admin tag from all bots };

// Marks users as inactive if they haven't edited in a month or more UserTagsJS.modules.inactive = 30;

/********************/ /* AutoEditDropdown */ /********************/

window.AutoEditDropdownConfig = { expandedAreaContribute: true, expandedAreaEdit: true };

/****************/ /* Auto Refresh */ /****************/

window.AjaxRCRefreshText = 'Auto-Refresh'; window.AjaxRCRefreshHoverText = 'Automatically refresh the page'; window.ajaxPages = [ 'Special:WikiActivity', 'Special:RecentChanges', 'Special:Log' ]; window.ajaxRefresh = 30000;

/************/ /* AjaxDiff */ /************/

window.AjaxDiff = { expiry: 'infinite', reason: 'Vandalism' };

//////////////////////////////////////////////////////////////////////////////// //                             LIST OF IMPORTS                               // ////////////////////////////////////////////////////////////////////////////////

importArticles({   type: 'script',    articles: [        'u:dev:UserTags/code.js', // User tags        'u:dev:AjaxRC/code.js', // Auto Refresh        'u:dev:AjaxDiff/code.js', // Allows to inspect diffs and stay in WikiActivity        'u:dev:ReferencePopups/code.js', // Displays content of references on hover        'u:dev:BackToTopButton/code.js', // Adds 'Back to top' button in pages        'u:dev:View_Source/code.js', // Adds 'view source' link to edit dropdown        'u:dev:RevealAnonIP/code.js', // Replaces 'a wikia contributor' with IP address        'u:dev:AutoEditDropdown/code.js', // Automatically opens edit menu on hover        'u:dev:Countdown/code.js' // Countdown (this script must always be the last one to load)    ] });