MediaWiki:FANSUN.js

/* *  * @module                  FANSUN.js * @description             Script for official wiki dark theming. * @author                 Speedit * @version                0.9.0 * @license                CC-BY-SA 3.0 * @notes                  Install FANSUN.css stylesheet(s) on the official wiki to use this script. * */
 * (function (window, mw, $) {

// Double-run protection window.dev = window.dev || {}; if (window.dev.dark) { return; }   window.dev.dark = { active: false };

/**    * @class               FANSUN * @classdesc          The main FANSUN object */   var FANSUN = { /**        * Script logic for post-render dark theming. * @method         init */       init: function { // Scoping to official wikis +FANSUN CSS import if (               FANSUN.wikis.indexOf(mw.config.get('wgDBname')) === -1 ||                $(document.body).css('color').match(/\d+/g).slice(0, 3).reduce(function(a, c) { return +Number(a)+Number(c); }) < 459           ) {                return; }           // Create active conditional for script window.dev.dark.active = true; // Override sassParams mw.config.set('wgSassParams', FANSUN.sassParams); $.extend(sassParams, FANSUN.sassParams); // Dark theme class $(document.body).addClass(function {               if (window.dev.hasOwnProperty('colors')) {                    return [                        'oasis-dark-theme',                        'menu-dark',                        'page-dark'                    ].join(' ');                } else {                    return 'oasis-dark-theme';                }            }).removeClass([                'menu-bright',                'page-bright'            ].join(' ')); // Override post-render MediaWiki imports $([document.head, document.body]).each(function {               var o = new MutationObserver(function(M) { M.forEach(function(R) {                       [].slice.call(R.addedNodes).filter(FANSUN.isSASS).forEach(function(s) { var url = s.getAttribute('href'); Object.keys(FANSUN.sassUtil).forEach(function(mode) {                               FANSUN.sassUtil[mode](mode);                            }); });                   });                });                o.observe(this, { childList: true });            }); },       /**         * SASS parameters for use in JavaScript * @type           {Object.} */       sassParams: { 'background-dynamic': 'false', 'background-image': '', 'background-image-height': '801', 'background-image-width': '1700', 'color-body': '#2c343d', 'color-body-middle': '#2c343d', 'color-buttons': '#00b7e0', 'color-community-header': '#404a57', 'color-header': '#404a57', 'color-links': '#00c8e0', 'color-page': '#39424d', 'oasisTypography': 1, 'page-opacity': '100', 'widthType': 0 },       /**         * Database names for official wikis * @type           {Array.} */       wikis: [ 'wikia', 'ca', 'de', 'es', 'fiwikia', 'frfr', 'it', 'ja', 'kowikia', 'nlwikia', 'plwikia', 'ptcommunity', 'ruwikia', 'vicommunity', 'zh', 'dev', 'infobox', 'vstf', 'communitycouncil' ],       /**         * String caching for SASS * @type           {Object.} */       cache: { '/sass': '', '/__load': '' },       /**         * SASS filter for CSS imports * @method         isSass */       isSASS: function(n) { return (               n.nodeName.toLowerCase === 'link' &&                n.getAttribute('href').indexOf('sass') > -1 &&                n.getAttribute('href').indexOf('background-dynamic') > -1            ); },       /**         * @class           sassUtil * @classdesc      SASS filter for CSS imports */       sassUtil: { /**            * AssetManager imports * @method     __am */           '__am': function(mode) { if (url.indexOf(mode) === -1) { return; }               // Array processing for AssetManager link // https://slot1-images.wikia.nocookie.net/__am//sasses// var url_a = url.split('/'), sass_i = +url_a.indexOf(mode)+3, sass_s_new; // SASS parameter-string conversion if (FANSUN.cache[mode].length > 0) { sass_s_new = FANSUN.cache[mode]; } else { sass_s_new = $.param(FANSUN.sassParams); // Caching for our new SASS string FANSUN.cache[mode] = FANSUN.cache.length > 0 ? FANSUN.cache[mode] : sass_s_new; }               // URL insertion for new SASS parameters url_a.splice(sass_i, 1, sass_s_new); var url_new = url_a.join('/'); // URL setter s.setAttribute('href', url_new); },           /**             * ResourceLoader imports * @method     __load */           '__load': function(mode) { if (url.indexOf(mode) === -1) { return; }               // Array processing for ResourceLoader asset // https://slot1-images.wikia.nocookie.net/__load/-/cb%3D1518765819%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26%26sass_wordmark-font%3D %26skin%3D var url_a = url.split('/'), sass_bounds = [ 'only%3Dstyles%26', '%26sass_wordmark-font' ],                   sass_p_mw, sass_i = +url_a.indexOf(mode)+2, sass_s_mw; // SASS parameter-string conversion if (FANSUN.cache[mode].length > 0) { sass_s_mw = FANSUN.cache[mode]; } else { // Convert MediaWiki 'mwSassParams' into 'sassParams' format sass_p_mw = {}; for (var k in FANSUN.sassParams) { sass_p_mw['sass_' + k] = FANSUN.sassParams[k]; }                   sass_s_mw = $.param(sass_p_mw); // Caching for our new SASS string FANSUN.cache[mode] = FANSUN.cache.length > 0 ? FANSUN.cache[mode] : sass_s_mw; }               // URL parsing logic to replace SASS parameters var sass_rgx = new RegExp(sass_bounds.join('|')); var sass_a_url = sass_s_url.split(sass_rgx); sass_a_url.splice(1, 1, sass_bounds[0], sass_s_mw, sass_bounds[1]); // Creating new URL var sass_s_new = sass_a_url.join(''); url_a.splice(sass_i, 1, sass_s_new); var url_new = url_a.join('/'); // URL setter s.setAttribute('href', url_new); }       }    };

// Script bootloader mw.loader.using('mediawiki.util', FANSUN.init);

}(window, mediaWiki, jQuery));