Fandom Developers Wiki
Advertisement

Note: After publishing, 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 / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * @name        JSONLink
 * @description Adds link to JSON page that contains translations on scripts' docs pages
 * @author      Railfail536
 * @author      TheGoldenPatrik1
 * @license     CC-BY-SA 3.0
 * @status      Stable
 * @version     1.0
 */
mw.loader.using(['mediawiki.api', 'mediawiki.Title']).then(function() {
    // Config
    var config = mw.config.get([
        'wgCityId',
        'wgNamespaceNumber',
        'wgPageName',
        'wgCategories',
        'wgArticleId'
    ]);
    if (
        config.wgCityId !== '7931' || // Dev Wiki only
        config.wgNamespaceNumber !== 0 || // Main namepsace only
        !/JavaScript/.test(config.wgCategories.join()) || // Load only if page is in 'JavaScript' category
        config.wgArticleId === 0 ||
        window.JSONLinkLoaded // Double run prevention
    ) { return; }
    window.JSONLinkLoaded = true;

    var title = config.wgPageName,
        titleText = 'MediaWiki:Custom-' + title.replace(/\/.*/, '') /* Ignore subpages */ + '/i18n.json';
    new mw.Api().get({
        cb: Date.now,
        action: 'query',
        titles: titleText
    }).done(function(d) {
        var pages = d.query.pages;
        if (d.error || pages[-1]) { return; }

        // Prepend link
        $('#PageHeader ul.wds-list').prepend(
            $('<li>').append(
                $('<a>', {
                    href: mw.util.getUrl(titleText),
                    text: 'JSON'
                })
            )
        );
    });
});
Advertisement