MediaWiki:ImportJS

dev:AdminDashboard JS-Button/code.js

dev:GlobalEditcount/code.js (function {   if ($("#UserProfileMasthead").length === 0) {        return;    }    if(typeof window.dev === 'undefined' || typeof window.dev.i18n === 'undefined') {        importScriptPage('MediaWiki:I18n-js/code.js', 'dev');    }    mw.hook('dev.i18n').add(function(i18no) { i18no.loadMessages('GlobalEditcount').done(function(i18n) {           i18n.useUserLang;            var username = $("#UserProfileMasthead h1").text;            $.getJSON(mw.util.wikiScript('api'), { action: 'query', list: 'users', ususers: username, usprop: 'editcount', format: 'json' }, function(data) { if(!data.error && typeof data.query.users[0].editcount !== 'undefined' && $(".UserProfileMasthead .globaledit-details").length === 0) { $(".tally").first.after(                       $(' ', { class: 'globaledit-details discussion-details tally' })                            .append( $('', {                                   id: 'globaleditAllEditsByUser',                                    href: mw.util.wikiGetlink('Special:Editcount/' + username)                                }) .append(                                       $(' ')                                            .text(data.query.users[0].editcount.toLocaleString)                                    ) .append(                                       $(' ', { class: 'globaledit-label' })                                            .text(i18n.msg('globaleditcount').escape)                                    ) )                   );                    mw.hook('GlobalEditcount.loaded').fire; }               mw.util.addCSS('.UserProfileMasthead .globaledit-details{border-top:1px solid #c7c6c5;padding-top:10px;}.UserProfileMasthead .globaledit-details a:hover{color:#004983}.UserProfileMasthead .tally .globaledit-label{padding:5px 0;}'); });       });    }); });

dev:DiscussionsFeed.js function strPad(n) { return String("00" + n).slice(-2); } function updateContent(content, isMod, canBlock, arr) { for (var i = arr["_embedded"]["doc:posts"].length - 1; i > -1; i--) { var text = arr["_embedded"]["doc:posts"][i].rawContent; var user = arr["_embedded"]["doc:posts"][i]["createdBy"].name; var userId = arr["_embedded"]["doc:posts"][i]["createdBy"].id; var epoch = arr["_embedded"]["doc:posts"][i]["creationDate"].epochSecond; var postID = arr["_embedded"]["doc:posts"][i].id; var threadID = arr["_embedded"]["doc:posts"][i].threadId; var isReported = Boolean(arr["_embedded"]["doc:posts"][i].isReported); var forumName = arr["_embedded"]["doc:posts"][i].forumName; var dt = new Date(epoch * 1000); var formattedDate = strPad(dt.getHours) + ":" + strPad(dt.getMinutes) + ":" + strPad(dt.getSeconds); //Create HTML for date: var spanDate = document.createElement("span"); spanDate.className = "df-date"; var spanDateText = document.createTextNode(formattedDate + " — "); spanDate.appendChild(spanDateText); //Create HTML for message body: var aMessage = document.createElement("a"); aMessage.className = "df-content"; aMessage.href = "/d/p/" + threadID; aMessage.target = "_blank"; var aMessageText = document.createTextNode(text); aMessage.appendChild(aMessageText); //Create HTML for user: var aUser = document.createElement("a"); aUser.className = "df-user"; aUser.href = "/d/u/" + userId; aUser.target = "_blank"; var aUserText = document.createTextNode(" — " + user); aUser.appendChild(aUserText); //Create HTML for category: var spanCategory = document.createElement("span"); spanCategory.className = "df-category"; var spanCategoryText = document.createTextNode(" in " + forumName); spanCategory.appendChild(spanCategoryText); //Create block button if (canBlock) { var aBlock = document.createElement("a"); aBlock.className = "df-block"; aBlock.href = "/wiki/Special:Block/" + user; aBlock.target = "_blank"; var aBlockText = document.createTextNode(" (block)"); aBlock.appendChild(aBlockText); }       //Put everything together var par = document.createElement("p"); par.className = "df-entry"; if (isReported) { par.className += " df-reported"; }       par.appendChild(spanDate); par.appendChild(aMessage); par.appendChild(aUser); par.appendChild(spanCategory); if (canBlock) { par.appendChild(aBlock); }       content.insertBefore(par, content.firstChild); } } //TODO: enable end user to disable auto refresh function updateFeed(content, isMod, canBlock, epoch) { var rcLimit = 50; var dt = new Date(epoch * 1000 + 1); //since epochs are rounded down to the nearest second, add 1 ms to prevent requesting the last post a second time var request = new XMLHttpRequest; request.onreadystatechange = function { if(request.readyState == 4) { switch(request.status) { case 200: var arr = JSON.parse(request.responseText); updateContent(content, isMod, canBlock, arr); //fetch timestamp of newest post, required for next request if (arr["_embedded"]["doc:posts"].length > 0) { epoch = arr["_embedded"]["doc:posts"][0]["creationDate"].epochSecond; }               default: setTimeout(updateFeed, 120000, content, isMod, canBlock, epoch); //set new timer (2m) }       }    };    request.open("GET", "https://services.wikia.com/discussion/" + wgCityId + "/posts?limit=" + rcLimit + "&since=" + dt.toISOString + "&page=0&responseGroup=small&reported=false&viewableOnly=" + (!isMod).toString, true); request.setRequestHeader('Accept', 'application/hal+json'); request.send; } function initFeed(content, isMod, canBlock) { var rcLimit = 50; var request = new XMLHttpRequest; request.timeout = 30000; // 30 seconds request.ontimeout = function { content.innerHTML = "Unable to load discussions: The service is down or is not enabled for this domain."; };   request.onreadystatechange = function { if(request.readyState == 4) { switch(request.status) { case 200: var arr = JSON.parse(request.responseText); content.innerHTML = ''; updateContent(content, isMod, canBlock, arr); //fetch timestamp of newest post, required for next request var epoch = arr["_embedded"]["doc:posts"][0]["creationDate"].epochSecond; setTimeout(updateFeed, 120000, content, isMod, canBlock, epoch); //set new timer (2m) break; case 404: content.innerHTML = 'There are no posts.'; break; default: content.innerHTML = "Unable to load discussions: The service is down or is not enabled for this domain."; }       }    };    request.open("GET", "https://services.wikia.com/discussion/" + wgCityId + "/posts?limit=" + rcLimit + "&page=0&responseGroup=small&reported=false&viewableOnly=" + (!isMod).toString, true); request.setRequestHeader('Accept', 'application/hal+json'); request.send; } function createDiscussionsFeed { if(wgNamespaceNumber == -1 && wgTitle == "DiscussionsFeed") { //TODO: i18n make dictionary document.title = 'Discussions Feed - ' + wgSiteName; var canBlock = Boolean(wgUserGroups.indexOf('sysop') > -1 || wgUserGroups.indexOf('staff') > -1 || wgUserGroups.indexOf('helper') > -1 || wgUserGroups.indexOf('vstf') > -1); var isMod = Boolean(canBlock || wgUserGroups.indexOf('threadmoderator') > -1); if (window.skin == "oasis") { document.getElementById("PageHeader").getElementsByTagName("h1")[0].innerHTML = " Discussions Feed "; //Oasis skin title } else if (window.skin == "monobook") { document.getElementById("firstHeading").innerHTML = 'Discussions Feed '; //Monobook skin title }       var content = document.getElementById("mw-content-text"); content.innerHTML = 'Loading feed...  '; initFeed(content, isMod, canBlock); } } //include guard {   var j = -1; for (var i = 0; i < onloadFuncts.length && j < 0; i++) { if (onloadFuncts[i].name == "createDiscussionsFeed") { j = i;       } }   if (j < 0) { addOnloadHook(createDiscussionsFeed); } }

dev:DiscordIntegrator/code.js

(function {   'use strict';    var mconfig = mw.config.get([ 'skin', 'wgUserLanguage', 'wgUserName' ]),   /**     * Main object     * @static     */        DiscordIntegrator = {        /**         * Configuration for the plugin         * @property config         * @type {Object}         */        config: (window.DiscordIntegratorConfig || {}).siderail || {},        /**         * Preload resources         */        preload: function {            if(mconfig.skin !== 'oasis' && mconfig.skin !== 'wikia') {                this.init;                return;            }            mw.loader.using('mediawiki.api').then($.proxy(function {                var api = new mw.Api;                api.get({ action: "query", meta: "allmessages", ammessages: ["id", "title", "moduleHeight", "usePTB", "theme", "width", "height", "text", "logged-in"].map(function(el) {                       return "Custom-DiscordIntegrator-config-" + el;                    }).join("|"), amlang: mconfig.wgUserLanguage }).done($.proxy(function(d) {                   if(!d.error) {                        d.query.allmessages.forEach(function(el) { if(el['*']) { this.config[el.name.substring(32)] = el['*']; }                       }, this);                        this._loading = 0;                        if(this.config.text) {                            ++this._loading;                            api.get({ action: "parse", text: this.config.text }).done($.proxy(function(d) {                               if(!d.error) {                                    this.config.text = d.parse.text["*"];                                    if(--this._loading === 0) {                                        this.init;                                    }                                }                            }, this));                        }                        if(this.config.title) {                            ++this._loading;                            api.get({ action: "parse", text: this.config.title }).done($.proxy(function(d) {                               if(!d.error) {                                    this.config.title = d.parse.text["*"];                                    if(--this._loading === 0) {                                        this.init;                                    }                                }                            }, this));                        }                        if(this._loading === 0) {                            this.init;                        }                    }                }, this));            }, this));        },        /**         * Initializing         */        init: function {            if(this.config.id && $('#WikiaRail').length > 0) {                var clas = $('#WikiaRail').attr('class');                if(clas && clas.split(/\s+/).indexOf('loaded') === -1) {                    $('#WikiaRail').on('afterLoad.rail', this.insertToSiderail.bind(this)); } else { this.insertToSiderail; }           }            if($(".DiscordIntegrator").length > 0) { this.insertToContent; }       },        /**         * Inserting the widget to siderail */       insertToSiderail: function { var filter = $('#TOP_RIGHT_BOXAD, #NATIVE_TABOOLA_RAIL, .content-review-module').last, // TODO: Insert some user configuration here el = $(' ', { class: 'DiscordIntegratorModule rail-module' }); if(this.config.title) { el.append(                   $(' ', { class: 'activity-heading' })                        .html(this.config.title)                ); }           if(this.config.text) { el.append(                   $(' ', { id: 'DiscordIntegratorModuleText' })                        .html(this.config.text)                ); }           el.append(this.generateContent(this.config)); if(filter.length > 0) { el.insertAfter(filter); } else { $('#WikiaRail').prepend(el); }           mw.util.addCSS(".DiscordIntegratorModule { height: " + Number(this.config.moduleHeight || 500) + "px; }"); mw.hook('DiscordIntegrator.added').fire; },       /**         * Finding the designated places in content * in which to place the widget and placing it        */ insertToContent: function { $(".DiscordIntegrator").each(function(cabbage, el) {               el = $(el);                el.html(this.generateContent(el.data));            }.bind(this)); },       /**         * Generating widget content from an object * @todo i18n * @return [String] content of the widget */       generateContent: function(config) { return config.id ? ((config.loggedIn === true || Boolean(config["logged-in"]) === true) && !mconfig.wgUserName) ? "Please log in to see this widget" : mw.html.element('iframe', {               src: "https://" + (String(config.usePTB) === "true" ? "ptb." : "") +                    "discordapp.com/widget?id=" +                     config.id +                     "&theme=" +                     (config.theme === "light" ? "light" : "dark"),               width: config.width || "100%",                height: config.height || "90%",                allowtransparency: "true",                frameborder: "0"            }) : "Error: ID of the widget is not supplied"; }   };    $($.proxy(DiscordIntegrator.preload, DiscordIntegrator)); });

dev:YoutubePlayer/code.js

dev:View Source/code.js