MediaWiki:Common.js

De Inkipedia
Revisión del 16:35 18 jul 2022 de Shahar (discusión | contribs.) (Se ha deshecho la revisión 18035 de A22PG (disc.) Already in All.js which is both common and mobile.)

Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.

  • Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
  • Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
  • Internet Explorer/Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
  • Opera: Presiona Ctrl+F5.
/* Any JavaScript here will be loaded for all users on every page load. */

/* MediaWiki:All.js */
mw.loader.load('//es.splatoonwiki.org/wiki/MediaWiki:All.js?action=raw&ctype=text/javascript');

// ================================================================================
// Pikan -- the analyzer on the edit page
// ================================================================================
$.getScript('//www.pikminwiki.com/MediaWiki:Pikan-core.js'
+ '?action=raw&ctype=text/javascript', function () {
  mw.loader.load('//splatoonwiki.org/w/index.php?title=User:Espyo/pikan-inkipedia.js'
  + '&action=raw&ctype=text/javascript');
});

// ================================================================================
// Injection into Upload Wizard for custom licensing and categories
// ================================================================================
//https://commons.wikimedia.org/wiki/Commons:Upload_Wizard/Editing#License_options
//https://www.mediawiki.org/wiki/Extension:UploadWizard/CustomWikiTextLicenseFeature

if ("UploadWizard" === mw.config.get('wgCanonicalSpecialPageName')) {
  mw.loader.using('ext.uploadWizard', function () {
    try {
      var autoAdd = mw.config.get('UploadWizardConfig').autoAdd;
 
      // Add a custom category to all my upload wizard uploads
      // autoAdd.categories.push("Images");

      // Add a custom license tag to all my files uploaded using the sorcerer
      autoAdd.wikitext += "{{fairuse}}";
 
    } catch (ex) {
      mw.log("Injecting custom-category into UploadWizard failed.", ex);
    }
  });
}

///////////////////////////////////////////////////////////////////////////////
//                               Gobbler Class                               //
///////////////////////////////////////////////////////////////////////////////

// Folds all infoboxes into a single, tabbed element

// Object constructor
var Gobbler = function() {

    // Check for a gobbler object in the document
    this.element = document.getElementById("gobbler");
    if (!this.element) return;

    // Gobble all of the infoboxes on the page
    var elements = document.getElementsByClassName("tagInfobox");
    var tabs     = [];
    for (var x = 0; x < elements.length; x++)
        tabs.push(this.gobble(elements[x]));
    this.onTab(tabs[tabs.length - 1]);

    // Add the infoboxes and tab buttons to the gobbler element
    var tabStrip = document.createElement("div");
    tabStrip.style.textAlign = "left";
    if (tabs.length > 1)
        this.element.appendChild(tabStrip);
    for (var x = 0; x < tabs.length; x++) {
        tabStrip.appendChild(tabs[x].button);
        this.element.appendChild(tabs[x].element);
    }

};

// Process an infobox
Gobbler.prototype.gobble = function(element) {

    // Retrieve the infobox's hidden tab button element
    var button = element.getElementsByClassName("tagTab")[0];

    // Create a tab object using the contents of the element
    var tab = {
        button:        button,
        colorInactive: button.style.backgroundColor,
        colorActive:   button.style.outlineColor,
        element:       element,
        cssText:       element.style.cssText
    };

    // Configure element properties
    var that = this;
    element.style.cssText = "width: 100%; height: 100%; display: none;";
    button.style.display  = "inline";
    button.onmousedown    = function(e) {
        if (e.button == 0) that.onTab(tab);
    };
    return tab;
};

// Event handler for when a tab is selected/clicked
Gobbler.prototype.onTab = function(tab) {

    // Deselect the previous infobox
    if (this.current) {
        this.current.button.style.fontWeight      = "normal";
        this.current.button.style.backgroundColor = this.current.colorInactive;
        this.current.element.style.display        = "none";
    }

    // Select the new infobox
    this.element.style.cssText       = tab.cssText;
    tab.button.style.fontWeight      = "bold";
    tab.element.style.display        = "inline";
    tab.button.style.backgroundColor = tab.colorActive;
    this.current                     = tab;
};

$( document ).ready(function() {
    new Gobbler();
    // 3D/2D viewer
    $('.switch-to-3d').click(function() {
	    $('.container-2d').hide();
	    $('.viewer-3d, .viewer-3d-multi, .buttons-container-3d').show();
    });

    $('.switch-to-2d').click(function() {
	    $('.viewer-3d, .viewer-3d-multi, .buttons-container-3d').hide();
	    $('.container-2d').show();
    });
});

// ================================================================================
// Warning message in console to help prevent scams
// ================================================================================
setTimeout(function () {
    console.log("%cHold up squiddo!",
        "color:rgb(170, 220, 0);font-family:Splatoon2, sans-serif;font-size:40px")
    console.log("%cIf someone told you to paste something here, there is a 99% chance you're getting scammed!",
        "font-family:Splatoon2, sans-serif;font-size:15px")
    console.log("%cPasting anything here could give scammers access to your account",
        "color:red;font-family:Splatoon2, sans-serif;font-size:15px")
    console.log("%cUnless you know what you're doing, don't paste anything here!",
        "font-family:Splatoon2, sans-serif;font-size:25px")
}, 1500)