MediaWiki:Common.js

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

$(function {

"use strict";

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

/*****************/   /* Spoiler Alert */ /*****************/

// This script must always be the very first executed

// Enables the alerts only in articles within the category "Spoilers" if ($.inArray("Spoilers", mw.config.get('wgCategories')) > -1) {

// Alert var alert = '' + ' ' +       ' ';

// Inserts the alert 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) { // Inserts the alert if it's been more than one month since the last visit or the user has never visited the site $('#WikiaMainContentContainer').before(alert); document.getElementById("WikiaMainContentContainer").style.filter = "blur(15px)"; // Sets a blurring of 15px document.getElementById("WikiaMainContentContainer").style.WebkitFilter = "blur(15px)"; // Sets blurring in Webkit browsers var opacity = $('#WikiaPageBackground').css('opacity'); // Saves the original value of the opacity of the background document.getElementById("WikiaPageBackground").style.opacity = "1"; // Temporarily disables the opacity

// Actions when clicking yes or no           $('#yes').click(function  {                $('#spoiler-container').remove; // Removes the alert                document.getElementById("WikiaMainContentContainer").style.filter = "none"; // Removes the blurring                document.getElementById("WikiaMainContentContainer").style.WebkitFilter = "none"; // Removes the blurring in Webkit browsers                document.getElementById("WikiaPageBackground").style.opacity = opacity; // Restores the original opacity                localStorage.setItem("spoilerCache", thisVisit); // Saves the timestamp of this visit            }); $('#no').click(function {                $('#spoiler-alert').remove; // Removes the alert            }); }

// Adds button to rehide spoilers to the row of buttons $('#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');

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

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

/*************************************/       /* Random Episode, Calendar and Poll */ /*************************************/

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'], ['', 'div#home-poll'] ];       values.forEach(function (args) {            parse.apply(null, args);        });

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

var homeSocial = ' ';

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

}

////////////////////////////////////////////////////////////////////////////   //                             OTHER PAGES                                // ////////////////////////////////////////////////////////////////////////////

/***********************************/   /* Hides spoilers in Wiki Activity */ /***********************************/

if (mw.config.get('wgPageName') === 'Special:WikiActivity') { setInterval(function {            $(".activity-ns-2001:not(:contains(#SPOILERS))").css("display", "block");        }, 1000); }

});

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

$(window).load(function {

'use strict';

/**************/   /* Need Help? */   /**************/

// Module var needHelp = '' + ' Need Help? ' +       '' + '' + 'Releases dates of anime, manga and other AoT material? Check out our Calendar.' + 'Questions, theories, something to discuss? Visit our Forum</a>.</li>' + 'Opinions, news, thoughts to share? Write a Blog Post</a>.</li>' + 'Suggestions, complaints or another doubt? Contact an Administrator</a>.</li>' + '</ul>' + ' ';

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

// 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(needHelp); // Inserts module above Chat }           } else { // If it's an anonymous user $('.ForumActivityModule').first.before(needHelp); // Inserts module above either Forum Activity or Related Threads $('.WikiaBlogListingBox').before(needHelp); // Inserts module above Popular blog posts }       }

// Inserts it above Chat in other pages if ((namespaces.indexOf(mw.config.get('wgNamespaceNumber')) > -1 && typeof 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(needHelp); // Inserts module above Chat }

}

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

var socialModule = '<section class="module" id="SocialModule">' + ' Follow us! ' +       ' ' +    ' ';

$('.ChatModule').before(socialModule);

/*******************************************************/   /* Moves Community, Trending Fandom Articles, Insights */ /* and HotSpots modules to the bottom of the sidebar  */ /*******************************************************/

$('#WikiaRail').append($('.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</a></li>');

});

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

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

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

// Core configuration window.UserTagsJS = { modules: {}, tags: { bureaucrat: { u: 'Bureaucrat', link: 'Project:Administrators', order: -7 },       sysop: { 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 */ /****************/

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

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

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

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

importArticles({   type: 'script',    articles: [        'w:c: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        'w:c:dev:Countdown/code.js' // Countdown (this script must always be the last one to load)    ] });