Jump to content

MediaWiki:Common.js: Difference between revisions

From OkayXairen Wiki
No edit summary
No edit summary
Line 1: Line 1:
(function () {
(function () {
    // Skip special pages
     if (mw.config.get('wgNamespaceNumber') < 0) return;
     if (mw.config.get('wgNamespaceNumber') < 0) return;


     mw.loader.using('mediawiki.api').then(function () {
     var title = mw.config.get('wgPageName');


        var title = mw.config.get('wgPageName');
    var cssPage = 'Template:PageCSS/' + title + '.css';
        var cssPage = 'Template:PageCSS/' + title + '.css';
    var jsPage  = 'Template:PageJS/' + title + '.js';


         var api = new mw.Api();
    // Load CSS if present
    mw.loader.load(
         mw.util.getUrl(cssPage, { action: 'raw', ctype: 'text/css' }),
        'text/css'
    );


        api.get({
    // Load JS if present
            action: 'query',
    mw.loader.load(
            titles: cssPage,
        mw.util.getUrl(jsPage, { action: 'raw', ctype: 'text/javascript' }),
            format: 'json'
        'text/javascript'
        }).done(function (data) {
     );
            var pages = data.query.pages;
            var pageId = Object.keys(pages)[0];
 
            if (pageId !== "-1") {
                var cssUrl = mw.util.getUrl(cssPage, {
                    action: 'raw',
                    ctype: 'text/css'
                });
 
                mw.loader.load(cssUrl, 'text/css');
            }
        });
 
     });
})();
})();

Revision as of 22:43, 11 March 2026

(function () {
    // Skip special pages
    if (mw.config.get('wgNamespaceNumber') < 0) return;

    var title = mw.config.get('wgPageName');

    var cssPage = 'Template:PageCSS/' + title + '.css';
    var jsPage  = 'Template:PageJS/' + title + '.js';

    // Load CSS if present
    mw.loader.load(
        mw.util.getUrl(cssPage, { action: 'raw', ctype: 'text/css' }),
        'text/css'
    );

    // Load JS if present
    mw.loader.load(
        mw.util.getUrl(jsPage, { action: 'raw', ctype: 'text/javascript' }),
        'text/javascript'
    );
})();