User:TheGoldenPatrik1/common.js

/* Imports */ importArticles({   type: 'script',    articles: [        'FANSUN.js',        //'JSONLink.js'    ] });//End Imports */

/* (function {   // Scoping    var config = mw.config.get([ 'wgPageName', 'wgAction', 'wgCityId' ]);   if ( config.wgCityId !== '7931' || !(/List_of_JavaScript_enhancements|List_of_CSS_enhancements/g.test(config.wgPageName)) || $.getUrlVar('diff') || config.wgAction !== 'view' || window.EnhancementSearchLoaded ) {        return;    }    window.EnhancementSearchLoaded = true;    $('#mw-content-text').prepend( $(' ', {           attr: {                type: 'text',                placeholder: 'Search ' + (config.wgPageName == 'List_of_JavaScript_enhancements' ? 'JavaScript' : 'CSS'),               id: 'EnhancementSearch'            },            keyup: filter_scripts        }) );   var dd = [].slice.call(document.getElementsByTagName('dd')),    dt     = [].slice.call(document.getElementsByTagName('dt'));    function show_all {        $('.matched-text').each(function { this.parentElement.replaceChild(document.createTextNode(this.innerHTML), this); });       $('.enhancementsearch-hide, .enhancementsearch-keep').removeClass('enhancementsearch-hide enhancementsearch-keep');        $('#mw-content-text').removeClass('remove-clutter');    }    function show(d, t) {        d.className = t.className = 'enhancementsearch-keep';    }    function hide(d, t) {        d.className = t.className = 'enhancementsearch-hide';    }    function hide_clutter {        $('#mw-content-text').addClass('remove-clutter');    }    function includes(text, sub) {        text = text.toLowerCase;        sub = sub.toLowerCase;        var split = sub.split(' ').filter(Boolean),        i = split.length;        while (i--) {            if (text.indexOf(split[i]) == -1) {                return false;            }        }        return true;    }    function filter_scripts(e) {        var value = e.target.value;        if (!value) {            return show_all; }       hide_clutter; for (var i in dd) { var d = dd[i], t = dt[i], di = includes(d.textContent, value), ti = includes(t.textContent, value); if (di || ti) { show(d, t); } else { hide(d, t); }       }    }    importArticle({        type: 'style',        article: 'u:dev:MediaWiki:EnhancementSearch.css'    }); });

mw.loader.using(['mediawiki.api']).then(function {   // Variables    var config = mw.config.get([ 'wgCategories', 'wgCityId', 'wgNamespaceNumber', 'wgPageName', 'wgTitle' ]),       title = config.wgPageName.split('/'),        isLuaDoc = title[0] === 'Global_Lua_Modules',        isLuaModule = config.wgNamespaceNumber === 828,        isLua = isLuaDoc || isLuaModule;        isMediaWiki = config.wgNamespaceNumber === 8;        titleText = isLua ? 'Module:' + (isLuaModule ? config.wgTitle.replace(/\/.*/, ) : title[1]) + '/i18n' : 'MediaWiki:Custom-' + config[isMediaWiki ? 'wgTitle' : 'wgPageName'].replace(/\/.*/, ) + '/i18n.json',       api = new mw.Api,        list = $('.page-header__contribution-buttons .wds-list');    // Load Protection    if ( config.wgCityId !== '7931' || (           isLuaModule &&            title[1] == 'i18n'        ) || $(           '.pi-data-value a[href="/wiki/Help:System_messages"]'        ).exists || window.I18nLinkLoaded ) {        return;     }    window.I18nLinkLoaded = true;    /**     * @method click     * @description Creates the JSON page when clicked     */    function click  {        if ( confirm(               i18n.msg('confirm', titleText).plain            ) === true ) {           api.post({ action: 'edit', title: titleText, watchlist: 'nochange', text: '/*  */', token: mw.user.tokens.get('editToken'), summary: 'Creating via Script' }).done(function(data) { window.location.href = mw.util.getUrl(titleText); });       }    }    /**     * @method button     * @description Checks if the page exists and acts accordingly     */    function button  {        // Checks if page exists        api.get({ cb: Date.now, action: 'query', titles: titleText }).done(function(d) { if (d.error) { return; }           // Link if (!d.query.pages[-1]) { list.append(                   $('', { id: 'ca-' + isLua ? 'i18n' : 'json' }).append( $('', {                           text:                                i18n.msg( isLua ? 'luaText' : 'jsText' ).plain,                           title:                                i18n.msg( isLua ? 'luaTitle' : 'jsTitle' ).plain,                           href: mw.util.getUrl(titleText)                        }) )               );            }            // Create JSON Button else if (               !window.DisableCreateJSON &&                !isLua            ) { list.append(                   $('', { id: 'ca-create-json' }).append( $('', {                           text: i18n.msg('createText').plain,                            title: i18n.msg('createTitle').plain,                            click: click                        }) )               );            }        });    }    /**     * @method init     * @description Initiates the script     * @param {String} i18nData - Variable for I18n-js     */    function init (i18nData) {        i18n = i18nData;        if ( config.wgCategories.indexOf('JavaScript') !== -1 || isLua || (               isMediaWiki &&                new mw.Title(config.wgPageName).getExtension === 'js'            ) ) {           button;        }    }    // Load script	mw.hook('dev.i18n').add(function(i18n) { i18n.loadMessages('JSONLink').then(init); });	// Import	importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' }); });