MediaWiki:Cosmos.js

/* All JavaScript here will be loaded for users of the Cosmos skin */ $(function{ if(window.JSloaded){ return; }

$( "#discord-widget" ).html(' ');

window.JSloaded = true; if(mw.config.get('wgCanonicalSpecialPageName') == 'UpdateProfile'){ $('.page-Special_UpdateProfile div.profile-update:nth-of-type(1) > .profile-update-title').append('    Edit Bio'); }

if(mw.config.get('wgPageName') == "Project_New_America_(Earth-2:_Post-Crisis)"){ window.history.replaceState(null,null, "/wiki/Project:_New_America_(Earth-2:_Post-Crisis)"); } if(mw.config.get('wgPageName') == "DC_Multiverse_Wiki:New_America_(Earth-2:_Post-Crisis)"){ window.location.replace("/wiki/Project_New_America_(Earth-2:_Post-Crisis)"); } window.setInterval(function{   $('a[title="Project New America (Earth-2: Post-Crisis)"]').attr("title", "Project: New America (Earth-2: Post-Crisis)"); },0);

mw.config.set({'wgAjaxLicensePreview' : true}); if(mw.config.get('wgCanonicalSpecialPageName') == "AdminLinks" ){ $('#mw-content-text').html($('#mw-content-text').html.replace(/·/g, '•')); } if(mw.config.get('wgCanonicalSpecialPageName') == "AdminLinks" && !mw.config.get('wgUserGroups').includes('sysop')){ $('#firstHeading').html('Permission error'); $('title').html('Permission error - ' + mw.config.get("wgSiteName")); $('#mw-content-text').html(' You do not have permission to view admin links, for the following reason: You are not allowed to execute the action you have requested. '); }

if((mw.config.get("wgNamespaceNumber") == 2 || mw.config.get("wgNamespaceNumber") == 202) && $('#profile-top').length > 0 && mw.config.get("wgAction") == "view"){ if(!$('body').hasClass('mw-wiki-user-page') && !$('body').hasClass('mw-social-profile-page')){ $('body').addClass('mw-social-profile-page'); }

if(mw.config.get("wgPageName").replace('User_profile:', 'User:') == "User:TheDemon08"){ $('.hgroup').append(' Founder '); $('.hgroup').append('Team Lead: Titans '); }else if(mw.config.get("wgPageName").replace('User_profile:', 'User:') == "User:Universal_Omega"){ $('.hgroup').append('Team Lead: Stargirl '); }else if(mw.config.get("wgPageName").replace('User_profile:', 'User:') == "User:Zomlouis"){ $('.hgroup').append('Team Lead: The Flash (1990) '); }else if(mw.config.get("wgPageName").replace('User_profile:', 'User:') == "User:IC228"){ $('.hgroup').append('Team Lead: The Flash (2014) '); }else if(mw.config.get("wgPageName").replace('User_profile:', 'User:') == "User:Rman41"){ $('.hgroup').append('Team Lead: Superman Anthology '); } }

$.urlParam = function (name) { var results = new RegExp("[?&]" + name + "=([^&#]*)").exec(     window.location.href    ); if (results == null) { return null; }   return decodeURI(results[1]) || 0; }; $.extend({    _urlVars: null,    getUrlVars: function  {      if ($._urlVars === null) {        var i,          j,          hash,          hashes = window.location.search            .slice(window.location.search.indexOf("?") + 1)            .split("&");        $._urlVars = {};        for (i = 0, j = hashes.length; i < j; i++) {          hash = hashes[i].split("=");          $._urlVars[hash[0]] = hash[1];        }      }      return $._urlVars;    },    getUrlVar: function (name) {      return $.getUrlVars[name];    },  }); window.getElementsByClassName = function (oElm, strTagName, oClassNames) { var arrReturnElements = []; if (!oElm) { return arrReturnElements; }   if (typeof oElm.getElementsByClassName == "function") { var arrNativeReturn = oElm.getElementsByClassName(oClassNames); if (strTagName == "*") { return arrNativeReturn; }     for (var h = 0; h < arrNativeReturn.length; h++) { if (         arrNativeReturn[h].tagName.toLowerCase == strTagName.toLowerCase        ) { arrReturnElements[arrReturnElements.length] = arrNativeReturn[h]; }     }      return arrReturnElements; }   var arrElements = strTagName == "*" && oElm.all ? oElm.all : oElm.getElementsByTagName(strTagName); var arrRegExpClassNames = []; if (typeof oClassNames == "object") { for (var i = 0; i < oClassNames.length; i++) { arrRegExpClassNames[arrRegExpClassNames.length] = new RegExp(         "(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"        ); }   } else { arrRegExpClassNames[arrRegExpClassNames.length] = new RegExp(       "(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"      ); }   var oElement; var bMatchesAll; for (var j = 0; j < arrElements.length; j++) { oElement = arrElements[j]; bMatchesAll = !0; for (var k = 0; k < arrRegExpClassNames.length; k++) { if (!arrRegExpClassNames[k].test(oElement.className)) { bMatchesAll = !1; break; }     }      if (bMatchesAll) { arrReturnElements[arrReturnElements.length] = oElement; }   }    return arrReturnElements; }; mw.hook( 've.saveDialog.stateChanged' ).add( function { mw.loader.load('/w/index.php?title=MediaWiki:Standard Edit Summaries.js&action=raw&ctype=text/javascript'); });

mw.loader.using(["mediawiki.jqueryMsg", "mediawiki.api"], function { if ( mw.config.get("wgUserGroups").includes("autoconfirmed") === true && mw.config.get('wgPageName') == 'Special:MultiUpload' ) { $.when(mw.loader.using(["mediawiki.api"])).then(function  { return new mw.Api .get({       action: "query",        meta: "siteinfo",        siprop: "fileextensions",        format: "json",      }) .then(function (data) { var extensions = data.query.fileextensions,		e; var FileExtensions = [];	for ( e in extensions ) {     FileExtensions.push(extensions[e].ext);

} mw.config.set({'wgFileExtensions' :FileExtensions});

mw.loader.load('/w/index.php?title=MediaWiki:MultiUpload.js&action=raw&ctype=text/javascript'); }); }); }

// Have categories added to images from upload description if (mw.config.get("wgCanonicalSpecialPageName") === "Upload") { if (!$.getUrlVar("wpForReUpload")) jQuery(function ($) {       "use strict";        var $desc = $("#wpUploadDescription");        if ($desc.val) {          return; // If not empty then don't do anything (i.e. error message confirm page)        }

var params = { action: "parse", page: "Template:Default Upload Summary", format: "json", prop: "wikitext", };       var api = new mw.Api;

api.get(params).done(function (data) {         return $desc.val(data.parse.wikitext["*"]);        });

if (window.location.href.indexOf("wpForReUpload") > -1) { return; } else { function verifyLicense { if (!$("#wpLicense").val) { window.alert("Licensing must be complete."); return false; }         }          $desc.closest("form").submit(verifyLicense); }     });  }          if (mw.config.get("wgArticleId") == 0) {            if ( mw.config.get("wgNamespaceNumber") == 0 && ($.urlParam("action") == "edit" ||               $.urlParam("veaction") == "edit" ||                $.urlParam("veaction") == "editsource") ) {             var ParseParams = {                action: "parse",                page: "Template:AutoNewPageButtons",                format: "json",              };              var ParseAPI = new mw.Api;

ParseAPI.get(ParseParams).done(function (data) {               $(".firstHeading").before(data.parse.text["*"]);                $(".AutoNewPageButtons").replaceWith( " " +                   $(".AutoNewPageButtons") .html .replace(                       /Template:AutoNewPageButtons/g,                        mw.config.get("wgPageName")                      ) );               $('a[href*="&preload="]').attr("target", "_self");              }); }         } else { return; }     }); }); // *****************************************************  // * 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 = ""; }   // calculate the diff

if (diff % 60 == 1) { var left = (diff % 60) + " second "; } else { left = (diff % 60) + " seconds "; }   diff = Math.floor(diff / 60); if (diff % 60 == 1) { left = (diff % 60) + " minute " + left; } else { if (diff > 0) left = (diff % 60) + " minutes " + left; }

diff = Math.floor(diff / 60); if (diff % 24 == 1) { left = (diff % 24) + " hour " + left; } else { if (diff > 0) left = (diff % 24) + " hours " + left; }   diff = Math.floor(diff / 24); if (diff == 1) { left = diff + " day " + left; } else { 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   } } $(checktimers);