User:K6ka/SkinSwitchButton/code.js

From K6ka's Wiki
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Edge: Press Ctrl-Shift-Del, select Cached data and files, and click Clear
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
 * 14:12, January 26, 2015 (UTC)
 * SkinSwitchButton
 * http://dev.wikia.com/wiki/SkinSwitchButton
 * Adds a button for switching between Oasis and Monobook.
 * Supports oasis, venus, monobook and wikiamobile
 * @author: UltimateSupreme (http://dev.wikia.com/wiki/User:UltimateSupreme)
 */
// <source lang="javascript">
/*jshint browser:true, jquery:true */
/*global mw */

jQuery(function ($) {
    'use strict';
    if ($('.ca-skins-switch').length) {
        return;
    }
    var elem = mw.html,
        monobook = window.monoBookText || 'Monobook',
        oasis = window.oasisText || 'Oasis',
        mobile = window.mobileText || 'Mobile',
        qstring = (window.location.search) ? '&' : '?';

    function skinlink(myskin, skintext) {
        return elem.element('li', {}, new elem.Raw(
        elem.element('a', {
            href: (window.location.href).replace(/#.*/, '') + qstring + $.param({useskin: myskin}),
            title: 'See this page in ' + myskin + ' skin',
            'class': 'ca-skins-switch'
        }, skintext)));
    }

    var $monobook = skinlink('monobook', monobook),
        $oasis = skinlink('oasis', oasis),
        $mobile = skinlink('wikiamobile', mobile);

    if (mw.config.get('skin') === 'oasis') {
        $(window.WikiaBar.wikiaBarWrapperObj.find('.tools')).append($monobook, $mobile);
    } else {
        $('#p-cactions > .pBody > ul').append($oasis, $mobile);
    }
});

// </source>