MediaWiki:DiscordBanner.js

/** * @module             DiscordBanner * @description        Add a banner to a wiki's Discord. * @author             Americhino *                     Unai01 * @usingcodeby        KockaAdmiralac (AddRailModule) * @version            0.9.0 * @license            CC-BY-SA 3.0 * */ (function {    var loaded, loadQueue = [],        $rail = $('#WikiaRail'),        railClass = $rail.attr('class');        // Configuration    var config = window.DiscordBannerSettings || {},        bannerStyle = config.bannerStyle || '3';        inviteLink = config.inviteLink || 'wPrVUj4'; // Wikia Developers        prependToRail = config.prependToRail || true; // Prepends to rail by default    if (!$rail.exists) {        return;    }    function place($module) {        var $ads;        if (prependToRail) {            $ads = $('#top-right-boxad-wrapper, #NATIVE_TABOOLA_RAIL').last;            if ($ads.exists) {                $module.insertAfter($ads);            } else {                $rail.prepend($module);            }        } else {            $ads = $('.rail-sticky-module');            if ($ads.exists) {                $module.insertBefore($ads);            } else { $rail.append($module); }       }    }    function placeQueue { loaded = true; loadQueue.forEach(place); }   (window.DiscordBannerModules || ['MediaWiki:Custom-DiscordBanner-id']).forEach(function (el) {        $.get(mw.util.wikiScript('api'), { action: 'parse', text: '{' + '{' + el + '}}', title: mw.config.get('wgPageName'), format: 'json' }).done(function (d) { var $section = $(' ', {               'class': 'discordBanner rail-module',                'style': 'transform: scale(0.9) !important; margin-left: -2px !important;',                html: $('', { href: 'https://discord.gg/' + inviteLink }).append($(' ', {                   src: 'https://discordapp.com/api/guilds/' + d.parse.text['*'].replace(/[\s\S]*(\d{18})[\s\S]*/, '$1') + '/widget.png?style=banner' + bannerStyle                }))            }); if (loaded) { place($section); } else { loadQueue.push($section); }           mw.hook('wikipage.content').fire($section); mw.hook('DiscordBanner.module').fire(el); });   });    if (railClass && railClass.split(/\s+/).indexOf('loaded') === -1) { $rail.on('afterLoad.rail', placeQueue); } else { placeQueue; } });