User:Superwatery/common.js

(function($, mw) {   'use strict';    var config = mw.config.get([ 'wgCityId', 'wgUserName' ]);   if (config.wgCityId !== 2188264 || window.MatrixLoaded) {        return;    }    window.MatrixLoaded = true;    var Matrix = {        config: window.MatrixConfig || {},        init: function {            this.api = new mw.Api;            // eslint-disable-next-line max-len            this.spinner = '  ';            $('#my-tools-menu').append( $('').append(                   $('', { 'class': 'custom', 'text': 'Publish user activity' }).click($.proxy(this.click, this))               ) );       },        click: function {            $(' ', { css: { 'background': 'rgba(255, 255, 255, 0.5)', 'position': 'fixed', 'height': '100%', 'width': '100%', 'left': '0', 'top': '0', 'z-index': '1000000000' },               html: this.spinner, id: 'matrix-spinner' }).appendTo(document.body);           this.wikis = [];            this.getWikis;        },        getWikis: function(offset) {            $.get('https://community.fandom.com/wiki/Special:UserActivity', { uselang: 'en', offset: offset }), $.proxy(this.cbWikis, this);       },        cbWikis: function(data) {            var $data = $(data),                nextHref = $data.find('.TablePager_nav')                    .first                    .find('a')                    .eq(2)                    .attr('href');            $data.find('.user-activity__table-wrapper .mw-datatable > tbody > tr').each($.proxy(function(_, row) {                var $children = $(row).children,                    $wiki = $children.eq(0);                this.wikis.push({ editString: $children.eq(1).text.trim, groups: $children.eq(3).text.trim, lastEdit: $children.eq(2).text.trim, title: $wiki.text.trim, url: $wiki.find('a').attr('href').trim });           }, this));            if (nextHref) {                this.getWikis(new mw.Uri(nextHref).query.offset);            } else {                this.cbNirvana({ items: this.wikis, total: this.wikis.length, totalReturned: this.wikis.length });           }        },        cbNirvana: function(d) {            var urlRegex = /^https?:\/\/(.*)\.(?:wikia|fandom|gamepedia)\.(?:com|org)\/(?:([^/]+)\/?)?$/,                str = '\n' +                      '{| width="100%" class="mw-datatable sortable"\n' +                      '|-\n' +                      '! \n' +                      '! data-sort-type="number" | # of edits\n' +                      '! \n' +                      '! \n' +                      d.items.filter(function(item) { return !(config.private instanceof Array) || config.private.indexOf(item.url) === -1; }).map(function(item) { var match = urlRegex.exec(item.url), wiki = match[1]; if (match[2]) { wiki = match[2] + '.' + wiki; }                         urlRegex.lastIndex = 0; return '|-\n' + '| \'\'\'' + item.title + '\'\'\'\n' + '| ' + item.editString + '\n' + '| ' + item.lastEdit + '\n' + '| ' + item.groups; }).join('\n') +                     '\n|}';            this.api.post({ action: 'edit', title: 'User:' + config.wgUserName + '/matrix', text: str, token: mw.user.tokens.get('csrfToken'), summary: 'Updating wiki list with Matrix.js', minor: true, bot: true }).done($.proxy(this.cbAPI, this));       },        cbAPI: function(d) {            $('#matrix-spinner').remove;            if (!d.error && d.edit.result === 'Success') {                mw.notify('List of wikis successfully updated!', { type: 'success' });           }        }    };    mw.loader.using([ 'mediawiki.api', 'mediawiki.notify', 'mediawiki.Uri' ]).then($.proxy(Matrix.init, Matrix)); })(jQuery, mediaWiki);

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:WHAM/code.2.js',    ] });