<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.ragnarok.wiki/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3ADiscordIntegrator%2Fcode.js</id>
	<title>MediaWiki:DiscordIntegrator/code.js - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.ragnarok.wiki/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3ADiscordIntegrator%2Fcode.js"/>
	<link rel="alternate" type="text/html" href="https://www.ragnarok.wiki/index.php?title=MediaWiki:DiscordIntegrator/code.js&amp;action=history"/>
	<updated>2026-06-04T21:23:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://www.ragnarok.wiki/index.php?title=MediaWiki:DiscordIntegrator/code.js&amp;diff=121&amp;oldid=prev</id>
		<title>Halca: Created page with &quot;/**  * Name:        DiscordIntegrator  * Author:      KockaAdmiralac &lt;wikia@kocka.tech&gt;  * Description: Allows intergration with Discord [https://discord.com]  */ (function() {     &#039;use strict&#039;;     var mconfig = mw.config.get([         &#039;wgContentLanguage&#039;,         &#039;wgUserLanguage&#039;,         &#039;wgUserName&#039;     ]);     if (window.DiscordIntegratorLoaded) {         return;     }     window.DiscordIntegratorLoaded = true;     /**      * Main object      * @static      */     v...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.ragnarok.wiki/index.php?title=MediaWiki:DiscordIntegrator/code.js&amp;diff=121&amp;oldid=prev"/>
		<updated>2023-12-09T20:18:30Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;*  * Name:        DiscordIntegrator  * Author:      KockaAdmiralac &amp;lt;wikia@kocka.tech&amp;gt;  * Description: Allows intergration with Discord [https://discord.com]: &lt;/span&gt; (function() {     &amp;#039;use strict&amp;#039;;     var mconfig = mw.config.get([         &amp;#039;wgContentLanguage&amp;#039;,         &amp;#039;wgUserLanguage&amp;#039;,         &amp;#039;wgUserName&amp;#039;     ]);     if (window.DiscordIntegratorLoaded) {         return;     }     window.DiscordIntegratorLoaded = true;     &lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;*      * Main object      * @static: &lt;/span&gt;     v...&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;/**&lt;br /&gt;
 * Name:        DiscordIntegrator&lt;br /&gt;
 * Author:      KockaAdmiralac &amp;lt;wikia@kocka.tech&amp;gt;&lt;br /&gt;
 * Description: Allows intergration with Discord [https://discord.com]&lt;br /&gt;
 */&lt;br /&gt;
(function() {&lt;br /&gt;
    &amp;#039;use strict&amp;#039;;&lt;br /&gt;
    var mconfig = mw.config.get([&lt;br /&gt;
        &amp;#039;wgContentLanguage&amp;#039;,&lt;br /&gt;
        &amp;#039;wgUserLanguage&amp;#039;,&lt;br /&gt;
        &amp;#039;wgUserName&amp;#039;&lt;br /&gt;
    ]);&lt;br /&gt;
    if (window.DiscordIntegratorLoaded) {&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    window.DiscordIntegratorLoaded = true;&lt;br /&gt;
    /**&lt;br /&gt;
     * Main object&lt;br /&gt;
     * @static&lt;br /&gt;
     */&lt;br /&gt;
    var DiscordIntegrator = {&lt;br /&gt;
        /**&lt;br /&gt;
         * Configuration for the plugin&lt;br /&gt;
         * @property config&lt;br /&gt;
         * @type {Object}&lt;br /&gt;
         */&lt;br /&gt;
        config: (window.DiscordIntegratorConfig || {}).siderail || {},&lt;br /&gt;
        /**&lt;br /&gt;
         * Preloads translations.&lt;br /&gt;
         */&lt;br /&gt;
        imported: function(i18n) {&lt;br /&gt;
            $.when(&lt;br /&gt;
                window.dev.i18n.loadMessages(&amp;#039;DiscordIntegrator&amp;#039;, {&lt;br /&gt;
                    cacheVersion: 3&lt;br /&gt;
                }),&lt;br /&gt;
                mw.loader.using(&amp;#039;mediawiki.api&amp;#039;)&lt;br /&gt;
            ).then(this.preload.bind(this));&lt;br /&gt;
        },&lt;br /&gt;
        /**&lt;br /&gt;
         * Preload resources&lt;br /&gt;
         */&lt;br /&gt;
        preload: function(i18n) {&lt;br /&gt;
            this.i18n = i18n;&lt;br /&gt;
            mw.hook(&amp;#039;wikipage.content&amp;#039;).add(this.insertToContent.bind(this));&lt;br /&gt;
            this.api = new mw.Api();&lt;br /&gt;
            this.api.get({&lt;br /&gt;
                action: &amp;#039;query&amp;#039;,&lt;br /&gt;
                meta: &amp;#039;allmessages&amp;#039;,&lt;br /&gt;
                ammessages: [&lt;br /&gt;
                    &amp;#039;id&amp;#039;,&lt;br /&gt;
                    &amp;#039;title&amp;#039;,&lt;br /&gt;
                    &amp;#039;moduleHeight&amp;#039;,&lt;br /&gt;
                    &amp;#039;theme&amp;#039;,&lt;br /&gt;
                    &amp;#039;width&amp;#039;,&lt;br /&gt;
                    &amp;#039;height&amp;#039;,&lt;br /&gt;
                    &amp;#039;text&amp;#039;,&lt;br /&gt;
                    &amp;#039;logged-in&amp;#039;,&lt;br /&gt;
                    &amp;#039;footer&amp;#039;,&lt;br /&gt;
                    &amp;#039;username&amp;#039;&lt;br /&gt;
                ].map(function(el) {&lt;br /&gt;
                    return &amp;#039;Custom-DiscordIntegrator-config-&amp;#039; + el;&lt;br /&gt;
                }).join(&amp;#039;|&amp;#039;),&lt;br /&gt;
                amlang: mconfig.wgUserLanguage === &amp;#039;qqx&amp;#039; ?&lt;br /&gt;
                    mconfig.wgContentLanguage :&lt;br /&gt;
                    mconfig.wgUserLanguage,&lt;br /&gt;
                uselang: &amp;#039;content&amp;#039;, // T97096&lt;br /&gt;
                smaxage: 300,&lt;br /&gt;
                maxage: 300&lt;br /&gt;
            }).done((function(d) {&lt;br /&gt;
                if (!d.error) {&lt;br /&gt;
                    d.query.allmessages.forEach(function(el) {&lt;br /&gt;
                        if(el[&amp;#039;*&amp;#039;]) {&lt;br /&gt;
                            this.config[el.name.substring(32)] = el[&amp;#039;*&amp;#039;];&lt;br /&gt;
                        }&lt;br /&gt;
                    }, this);&lt;br /&gt;
                    this._loading = 0;&lt;br /&gt;
                    [&amp;#039;text&amp;#039;, &amp;#039;title&amp;#039;, &amp;#039;footer&amp;#039;].forEach(this.parse, this);&lt;br /&gt;
                    if (this._loading === 0) {&lt;br /&gt;
                        this.init();&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }).bind(this));&lt;br /&gt;
        },&lt;br /&gt;
        /**&lt;br /&gt;
         * Parse the configuration that needs to be parsed&lt;br /&gt;
         */&lt;br /&gt;
        parse: function(msg) {&lt;br /&gt;
            if (this.config[msg]) {&lt;br /&gt;
                ++this._loading;&lt;br /&gt;
                this.api.get({&lt;br /&gt;
                    action: &amp;#039;parse&amp;#039;,&lt;br /&gt;
                    text: this.config[msg],&lt;br /&gt;
                    // Also cache the individual parser outputs of messages for anonymous users.&lt;br /&gt;
                    // This can be a bit more aggressive as the cache varies on the&lt;br /&gt;
                    // actual message text, which often contains no wikitext at all.&lt;br /&gt;
                    smaxage: 86400,&lt;br /&gt;
                    maxage: 86400&lt;br /&gt;
                }).done((function(d) {&lt;br /&gt;
                    if (!d.error) {&lt;br /&gt;
                        this.config[msg] = d.parse.text[&amp;#039;*&amp;#039;];&lt;br /&gt;
                        if (--this._loading === 0) {&lt;br /&gt;
                            this.init();&lt;br /&gt;
                        }&lt;br /&gt;
                    }&lt;br /&gt;
                }).bind(this));&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
        /**&lt;br /&gt;
         * Initializing&lt;br /&gt;
         */&lt;br /&gt;
        init: function() {&lt;br /&gt;
            if (this.config.id &amp;amp;&amp;amp; $(&amp;#039;#WikiaRail&amp;#039;).length &amp;gt; 0) {&lt;br /&gt;
                var clas = $(&amp;#039;#WikiaRail&amp;#039;).attr(&amp;#039;class&amp;#039;);&lt;br /&gt;
                if (clas) {&lt;br /&gt;
                    var classSplit = clas.split(/\s+/);&lt;br /&gt;
                    if (classSplit.indexOf(&amp;#039;loaded&amp;#039;) === -1 &amp;amp;&amp;amp; classSplit.indexOf(&amp;#039;is-ready&amp;#039;) === -1) {&lt;br /&gt;
                        $(&amp;#039;#WikiaRail&amp;#039;).on(&amp;#039;afterLoad.rail&amp;#039;, this.insertToSiderail.bind(this));&lt;br /&gt;
                    } else {&lt;br /&gt;
                        this.insertToSiderail();&lt;br /&gt;
                    }&lt;br /&gt;
                } else {&lt;br /&gt;
                    this.insertToSiderail();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
        /**&lt;br /&gt;
         * Inserting the widget to siderail&lt;br /&gt;
         */&lt;br /&gt;
        insertToSiderail: function() {&lt;br /&gt;
            var filter = $(&amp;#039;#top-right-boxad-wrapper, #top-boxad-wrapper, #NATIVE_TABOOLA_RAIL, .content-review-module&amp;#039;).last();&lt;br /&gt;
            // TODO: Insert some user configuration here&lt;br /&gt;
            var el = $(&amp;#039;&amp;lt;div&amp;gt;&amp;#039;, { class: &amp;#039;DiscordIntegratorModule rail-module&amp;#039; });&lt;br /&gt;
            if (this.config.title) {&lt;br /&gt;
                el.append(&lt;br /&gt;
                    $(&amp;#039;&amp;lt;h2&amp;gt;&amp;#039;, {&lt;br /&gt;
                        &amp;#039;class&amp;#039;: &amp;#039;activity-heading&amp;#039;,&lt;br /&gt;
                        html: this.config.title.trim()&lt;br /&gt;
                    })&lt;br /&gt;
                );&lt;br /&gt;
            }&lt;br /&gt;
            if (this.config.text) {&lt;br /&gt;
                el.append(&lt;br /&gt;
                    $(&amp;#039;&amp;lt;p&amp;gt;&amp;#039;, {&lt;br /&gt;
                        id: &amp;#039;DiscordIntegratorModuleText&amp;#039;,&lt;br /&gt;
                        html: this.config.text&lt;br /&gt;
                    })&lt;br /&gt;
                );&lt;br /&gt;
            }&lt;br /&gt;
            el.append(this.generateContent(this.config));&lt;br /&gt;
            if (this.config.footer) {&lt;br /&gt;
                el.append(&lt;br /&gt;
                    $(&amp;#039;&amp;lt;p&amp;gt;&amp;#039;, {&lt;br /&gt;
                        id: &amp;#039;DiscordIntegratorModuleFooter&amp;#039;,&lt;br /&gt;
                        html: this.config.footer&lt;br /&gt;
                    })&lt;br /&gt;
                );&lt;br /&gt;
            }&lt;br /&gt;
            if (filter.length &amp;gt; 0) {&lt;br /&gt;
                el.insertAfter(filter);&lt;br /&gt;
            } else {&lt;br /&gt;
                $(&amp;#039;#WikiaRail&amp;#039;).prepend(el);&lt;br /&gt;
            }&lt;br /&gt;
            if (this.config.moduleHeight) {&lt;br /&gt;
                mw.util.addCSS(&amp;#039;.DiscordIntegratorModule { height: &amp;#039; + Number(this.config.moduleHeight) + &amp;#039;px; }&amp;#039;);&lt;br /&gt;
            }&lt;br /&gt;
            mw.hook(&amp;#039;DiscordIntegrator.added&amp;#039;).fire(el);&lt;br /&gt;
        },&lt;br /&gt;
        /**&lt;br /&gt;
         * Finding the designated places in content&lt;br /&gt;
         * in which to place the widget and placing it&lt;br /&gt;
         */&lt;br /&gt;
        insertToContent: function($content) {&lt;br /&gt;
            $content.find(&amp;#039;.DiscordIntegrator:not(.loaded)&amp;#039;).each((function(cabbage, el) {&lt;br /&gt;
                el = $(el);&lt;br /&gt;
                el.html(this.generateContent(el.data()))&lt;br /&gt;
                  .addClass(&amp;#039;loaded&amp;#039;);&lt;br /&gt;
            }).bind(this));&lt;br /&gt;
        },&lt;br /&gt;
        /**&lt;br /&gt;
         * Determines the theme of the widget.&lt;br /&gt;
         * @param {string} config Configured theme&lt;br /&gt;
         * @return {string} &amp;#039;light&amp;#039; or &amp;#039;dark&amp;#039; depending on the wiki theme and configuration&lt;br /&gt;
         */&lt;br /&gt;
        determineTheme: function(config) {&lt;br /&gt;
            // If explicitly configured to light or dark.&lt;br /&gt;
            if (config === &amp;#039;dark&amp;#039;) {&lt;br /&gt;
                return &amp;#039;dark&amp;#039;;&lt;br /&gt;
            }&lt;br /&gt;
            if (config === &amp;#039;light&amp;#039;) {&lt;br /&gt;
                return &amp;#039;light&amp;#039;;&lt;br /&gt;
            }&lt;br /&gt;
            // If not configured, and the current FandomDesktop theme is set.&lt;br /&gt;
            if ($(&amp;#039;body&amp;#039;).hasClass(&amp;#039;theme-fandomdesktop-light&amp;#039;)) {&lt;br /&gt;
                return &amp;#039;light&amp;#039;;&lt;br /&gt;
            }&lt;br /&gt;
            if ($(&amp;#039;body&amp;#039;).hasClass(&amp;#039;theme-fandomdesktop-dark&amp;#039;)) {&lt;br /&gt;
                return &amp;#039;dark&amp;#039;;&lt;br /&gt;
            }&lt;br /&gt;
            // Otherwise, default to dark.&lt;br /&gt;
            return &amp;#039;dark&amp;#039;;&lt;br /&gt;
        },&lt;br /&gt;
        /**&lt;br /&gt;
         * Generating widget content from an object&lt;br /&gt;
         * @return {string} Content of the widget&lt;br /&gt;
         */&lt;br /&gt;
        generateContent: function(config) {&lt;br /&gt;
            if (!config.id || !String(config.id).match(/\d{17,19}/)) {&lt;br /&gt;
                return this.i18n.msg(&amp;#039;error&amp;#039;).parse();&lt;br /&gt;
            }&lt;br /&gt;
            if (&lt;br /&gt;
                (&lt;br /&gt;
                    config.loggedIn === true ||&lt;br /&gt;
                    Boolean(config[&amp;#039;logged-in&amp;#039;]) === true &amp;amp;&amp;amp;&lt;br /&gt;
                    config[&amp;#039;logged-in&amp;#039;] !== &amp;#039;false&amp;#039; &amp;amp;&amp;amp;&lt;br /&gt;
                    config[&amp;#039;logged-in&amp;#039;] !== &amp;#039;{{{loggedIn}}}&amp;#039;&lt;br /&gt;
                ) &amp;amp;&amp;amp; !mconfig.wgUserName&lt;br /&gt;
            ) {&lt;br /&gt;
                return this.i18n.msg(&amp;#039;login&amp;#039;).parse();&lt;br /&gt;
            }&lt;br /&gt;
            var username = config.username === &amp;#039;@disabled&amp;#039; ?&lt;br /&gt;
                 &amp;#039;&amp;#039; :&lt;br /&gt;
                 config.username === &amp;#039;@function&amp;#039; &amp;amp;&amp;amp;&lt;br /&gt;
                 typeof window.DiscordIntegratorGetUsername === &amp;#039;function&amp;#039; ?&lt;br /&gt;
                     window.DiscordIntegratorGetUsername() :&lt;br /&gt;
                     config.username || mconfig.wgUserName;&lt;br /&gt;
            return mw.html.element(&amp;#039;iframe&amp;#039;, {&lt;br /&gt;
                src: &amp;#039;https://discord.com/widget?id=&amp;#039; + config.id +&lt;br /&gt;
                     &amp;#039;&amp;amp;theme=&amp;#039; + this.determineTheme(config.theme) +&lt;br /&gt;
                     &amp;#039;&amp;amp;username=&amp;#039; + encodeURIComponent(username),&lt;br /&gt;
                width: config.width || &amp;#039;100%&amp;#039;,&lt;br /&gt;
                height: config.height || &amp;#039;400px&amp;#039;,&lt;br /&gt;
                allowtransparency: &amp;#039;true&amp;#039;,&lt;br /&gt;
                frameborder: &amp;#039;0&amp;#039;,&lt;br /&gt;
                title: this.i18n.msg(&amp;#039;title&amp;#039;).plain()&lt;br /&gt;
            });&lt;br /&gt;
        }&lt;br /&gt;
    };&lt;br /&gt;
    importArticle({&lt;br /&gt;
        type: &amp;#039;script&amp;#039;,&lt;br /&gt;
        article: &amp;#039;u:dev:MediaWiki:I18n-js/code.js&amp;#039;&lt;br /&gt;
    }).then(DiscordIntegrator.imported.bind(DiscordIntegrator));&lt;br /&gt;
})();&lt;/div&gt;</summary>
		<author><name>Halca</name></author>
	</entry>
</feed>