User:Fngplg/global.js

!function { // adds reg date to masthead. fngplg@2019 var $target = $('.masthead-info .details'), user = wgPageName.split(/\:|\//).pop; if (!$target.length) return; mw.loader.using(['mediawiki.api']).done(function {       new mw.Api.get({ action: 'query', list: 'users', ususers: user, usprop: 'registration' })       .done(function(data) { if (!data || !data.query || data.error || !data.query.users) return; data = data.query.users[0]; if (!data) return; var $li = $('', {text: ' ' + new Date(data.registration).toLocaleDateString('ru-RU')}) .prepend($(' ', {text: 'Регистрация'})); $target.find('ul:first').append($li); });   }); }; //redirect mw.log to debug window.fngconsole = window.fngconsole || window.console.log; window.console.log = function { var a = Array.prototype.slice.call(arguments); if (a[0] === '') { window.console.debug.apply(window.console, a); } else { window.fngconsole.apply(window.console, a); } }; // ajaxrc config (window.ajaxSpecialPages = window.ajaxSpecialPages || []).push('WikiActivity', 'Recentchanges'); // ucp config (window.fng = window.fng || {}).ucp = window.fng.ucp || {}; fng.ucp.moreactions = (fng.ucp.moreactions || []).concat([   {        id: 'nolp',        action: 'nolp=1',        caption: 'no linkpreview',        title: 'turn the shit off',    }, ]);

-function { var scounter = '.wds-global-navigation__notifications-counter#onSiteNotificationsCount', mooptions = {characterData: !0, childList: !0}, mo = new MutationObserver(function(e) {           // basically, we don't care about records. mutation itself is a sign            var addedNodes = e.map(function(v) {return v.addedNodes.length ? [].slice.call(v.addedNodes) : null}).flat.filter(Boolean);           console.log('mo txt', $(scounter).text, e, addedNodes);            if (!$(scounter).text) return;// nothing to do here        }); mo.observe($(scounter).get(0), mooptions); // debug mo.observe($('.wds-global-navigation__notifications-counter:not(#onSiteNotificationsCount)').get(0), mooptions); }; (function($) {   //window.pPreview = window.pPreview || {};    //window.pPreview.apid = !0;    //window.pPreview.debug = 1;    /*    window.pPreview = $.extend(true, window.pPreview, { tlen: 450, delay: 30, RegExp: {iparents: ['#IgnorePreview', 'div[data-ignore-me=1]', '.tabs'], onlyinclude : ['.LinkPreviewText', '[data-include-me=1]'],},});   */    var debug = $.getUrlVar('debug');    var scriptUrl = 'https://dev.fandom.com/load.php?mode=articles&only=scripts&articles=ViewRemoved/code.js|AjaxRC/code.js|CodeQuickLinks/code.js|View Source/code.js|Wikificator.js|NewCategoriesLocalizedFilter.js|UnifiedControlPanel.js|CategorySorter.js|CopyUrlWithCanonicalNamespace.js';    if (wgCityId != 105213) {        // ru.borderlands: 105213        window.log = window.log ? window.log : function{return console.log.apply(this, arguments);};        window.nQuoteSettings = $.extend(true, window.nQuoteSettings, { //debug: false, useQuoteTemplate: false, quoteStyle: 'border-width:1px;border-style:ridge;', });       scriptUrl = scriptUrl + '|LinkPreview/code.js|CommentPreview/code.js' +            '|Quotes.js';//'|w:c:ru.borderlands:mediawiki:Common.js/Quotes.js';    }    mw.loader.load(scriptUrl + (debug ? '&debug=1' : ''));    $(function { //replace /message_wall: to /user: for avatars $('.speech-bubble-avatar a').each(function(i,v){v.href = v.href.replace(/(.*\/).*?:/, '$1User:')}); });   //отключение ссылок в recentchanges, иногда посылающих на #    if (wgCanonicalSpecialPageName === 'Recentchanges') {        $('body').on('click', '.mw-enhanced-rc .mw-collapsible-toggle a', function(e){e.preventDefault});    }    //add encode/decode button to diffs    $('.diff-ntitle').append($(' ', {class: 'wds-button wds-is-secondary wds-is-squished', text: 'euc', style: 'position:absolute;right:0;'}).on('click', function(e){$('.diffchange').each(function{var $this=$(this);$this.text($this.data('encoded')?decodeURIComponent($this.text):encodeURIComponent($this.text));$this.data('encoded', !$this.data('encoded'));});}));    //    if (wgNamespaceNumber === 2000) $('.thread-left a').each(function(i,v) {v.title = v.innerText});    $.fn.filterByData = function(prop, val) {        return this.filter( function { if (!!val) { return $(this).data(prop) == val; }               return !!$(this).data(prop); }       );    };    (function { //test mode everywhere if (window.wgContentReviewTestModeEnabled) return; var hs = '.wds-community-header__top-container .wds-community-header__wiki-buttons'; var btn = $('', {class: 'wds-button wds-is-squished wds-is-secondary', text: 'T', href: '#', id: 'nbtntestmode', title: 'test mode'}); $(hs).append(btn); $('body').on('click', '.content-review-module-test-mode-enable, #nbtntestmode', function(e) {           e.preventDefault;            e.stopPropagation;            var data = {pageId: wgArticleId, wikiId: wgCityId, editToken: mw.user.tokens.get('editToken')};            $.nirvana.sendRequest({controller: 'ContentReviewApiController', method: 'enableTestMode', data: data, callback: function { var qs = new Wikia.Querystring; qs.addCb.goTo; },               onErrorCallback: function { console.error('test mode enabler error', arguments); }           });//sendrequest        });//onclick });//test mode everywhere   $(function  { //another jspad //https://stackoverflow.com/a/19961519 HTMLTextAreaElement.prototype.insertAtCaret = function (text) { text = text || ''; if (document.selection) { // IE           this.focus; var sel = document.selection.createRange; sel.text = text; } else if (this.selectionStart || this.selectionStart === 0) { // Others var startPos = this.selectionStart; var endPos = this.selectionEnd; this.value = this.value.substring(0, startPos) + text + this.value.substring(endPos, this.value.length); this.selectionStart = startPos + text.length; this.selectionEnd = startPos + text.length; } else { this.value += text; }       };//insertatcaret function btnClick (e) { if (e && e.preventDefault) e.preventDefault; gui.find('textarea').val(previousText); $('body').prepend(gui); gui.show.find('textarea').focus; }//btnclick function btnBClick (e) { $(' ', {type: 'text/javascript', text: gui.find('textarea').val}).prependTo($('head')); $(myname).remove; }//btnbclick var myname = '#ngui'; var previousText = ''; var hs = '.wds-community-header__top-container .wds-community-header__wiki-buttons'; var btn = $('', {class: 'wds-button wds-is-squished wds-is-secondary', text: 'JS', href: '#', id: 'nbtnshowgui', title: 'js (ctrl+bckspc)'}); var gui = $(' ', {id: myname.slice(1), style: 'position:absolute;left:0;top:100px;width:100%;height:90%;z-index:10000;visibility:visible;'}); var guib = $(' ', {type: 'button', class: 'wikia-button', value: 'start', id: 'nbtnstart'}); var guit = $(' ', {id: 'ntxtscript', style: 'display:block;margin: 0 5%;width:80%;height:auto;min-height:100px;max-height:80%;'}); gui.append(guib).append(guit); if ($(hs).length) { //oasis $(hs).append(btn); } else { //monobook $('#p-personal .pBody ul').append(btn); }//append js button $('body').on('keydown', function (e) {           if (e.ctrlKey && e.keyCode === 8) { //ctrl+bckspc                btnClick;                return false;            }        });//body keydown $('body').on('click', '#nbtnshowgui', btnClick); $('body').on('click', myname + ' #nbtnstart', btnBClick); $('body').on('keydown', myname + ' #ntxtscript', function (e) {           if (e.keyCode >= 37 && e.keyCode <= 40) return true; //arrows            var $this = $(myname + ' #ntxtscript');            switch (e.keyCode) {                case 9:                    $this.focus;                    $this.get(0).insertAtCaret('    ');                    return false;                case 13:                    if (e.shiftKey || e.ctrlKey) {                        previousText = $this.val;                        btnBClick;                        return false;                    }                    break;                case 27:                    previousText = $this.val;                    $(myname).remove;                    return false;            }            if ($this.val && $this.val.length > 100) $this.height($this.get(0).scrollHeight);        });//txt keydown });//js pad })(jQuery); !function { // sorts namespaces in the ns dropdowns on the following pages if (window.nsSorter || ['Prefixindex', 'Allpages', 'Recentchanges', 'Whatlinkshere'].indexOf(wgCanonicalSpecialPageName) === -1) return; function sorter ($content) { var $target, a, a1, $c = ($content instanceof jQuery) ? $content : $(document); switch (wgCanonicalSpecialPageName) { case 'Recentchanges': $target = $c.find('.mw-recentchanges-table .mw-input .dropdown-list').first; a = $target.find('li').toArray; a1 = a.sort(function(a, b) {return $(a).find('label').text.localeCompare($(b).find('label').text)}); break; case 'Allpages': case 'Prefixindex': case 'Whatlinkshere': $target = $c.find('select#namespace').first; a = $target.find('option').toArray; a1 = a.sort(function(a, b) {return a.label.localeCompare(b.label)}); break; }       if ($target && a1) { $target.empty.append(a1); ($target.find('[selected]:first').get(0) || {}).selected = true; }   }// sorter window.nsSorter = sorter; (window.ajaxCallAgain = (window.ajaxCallAgain || [])).push(sorter); sorter; }; (function ($) {   //add quick links to user    if ([2, 3, 500, 1200].indexOf(wgNamespaceNumber) === -1) return;    var $container = $(' links '),        $links = $(' '),        username = wgPageName.replace(/.*?\:/, ).replace(/\/.*/, ),        links = [            '//community.wikia.com/wiki/user:' + username + '/global.js',            wgArticlePath.replace('$1', 'user:' + username + '/common.js'),            wgArticlePath.replace('$1', 'user:' + username + '/wikia.js'),            '//community.wikia.com/wiki/user:' + username + '/global.css',            wgArticlePath.replace('$1', 'user:' + username + '/common.css'),            wgArticlePath.replace('$1', 'user:' + username + '/wikia.css'),        ];    links.forEach(function (link) { $links.append(           $('', { href: link, text: link.replace(/.*\//, '') })       );    });    $links.find('a').wrap('');    $container.append($links);    $('.page-header__title, .masthead-info [itemprop="name"]').after($container);    mw.util.addCSS('.userlinks-container{display:inline-block;vertical-align:top;background:inherit}\ .userlinks-links{display:none;position:absolute;z-index:1000;background:inherit}\ .userlinks-container:hover .userlinks-links{display:block}\ .userlinks-links li{list-style:none}'); })(jQuery); +function (config) { // adds go-to-line button to the tools menu @user:fngplg, 2018 if (config.loaded || ['edit', 'submit'].indexOf(window.wgAction) === -1) return; config.loaded = true; var $tools = $('#my-tools-menu'), $tool = $('', {class: 'overflow go-to-line'}), $a = $('', {href: '#', text: 'Go to line', title: 'Scrolls #wpTextbox1 to line x'}), lastLine = 0; $tool.append($a); $a.on('click', function(e) {       e.preventDefault;        //e.stopPropagation;        var $tbox = $('#wpTextbox1');        if (!$tbox.length) return;        var i, selStart,            alines = $tbox.text.split('\n'),            line = window.prompt('Enter line number, the', lastLine || alines.length - 1),            target = '';        lastLine = line === null ? lastLine : line;        line = (line && line > 0) ? line : 0;        line = line < alines.length ? line : (alines.length - 1);        target = alines[line];        if (!target) {            // empty line, go to next non-empty            for (i = line + 1; i < alines.length; i++) if (alines[i]) break;            target = alines[i];            if (!target) {                // line still empty, reverse                for (i = line - 1; i > -1; i--) if (alines[i]) break;                target = alines[i];            }        } selStart = $tbox.val.indexOf(target); if (selStart < 0) return;// should not be happened ever $tbox.focus; $tbox.get(0).setSelectionRange(selStart, selStart); $tbox.get(0).insertAtCaret(''); });   $tools.append($tool); }(window.goToLine = window.goToLine || {}); !function {    // freeze avatar animation    function freeze_image_helper(img) {        if (img instanceof jQuery.Event) img = img.target;        var canvas = document.createElement('canvas', {useCORS:!0});        canvas.height = img.height;        canvas.width = img.width;        canvas.classList = img.classList.value;        canvas.alt = img.alt;        canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);        $(img).hide;        img.after(canvas);    }// freeze_image_helper    function freeze_image(img, img1) {        if (typeof(img) === 'number') img = img1;        if (img instanceof jQuery) img.find('img.avatar:not(.frozen)').each(freeze_image);        if (img.tagName !== 'IMG' || img.classList.contains('frozen')) return;        img.classList.add('frozen');        if (img.complete) {            freeze_image_helper(img); } else { $(img).one('load', freeze_image_helper); }   }// freeze_image [].slice.call(document.getElementsByClassName('avatar')).forEach(freeze_image); mw.hook('wikipage.content').add(freeze_image); }; /* $(function {   // plural for mw:community-header-pages @user:fngplg, 2018    mw.loader.using(['mediawiki.language']).done(function { $('.wds-community-header__counter-label').text(mw.language.convertPlural($('.wds-community-header__counter-value').text,['страница', 'страниц', 'страницы'])); }); });

/* tabs 2 spaces !function { //https://stackoverflow.com/a/19961519 HTMLTextAreaElement.prototype.insertAtCaret = function (text) { text = text || ''; if (document.selection) { // IE       this.focus; var sel = document.selection.createRange; sel.text = text; } else if (this.selectionStart || this.selectionStart === 0) { // Others var startPos = this.selectionStart; var endPos = this.selectionEnd; this.value = this.value.substring(0, startPos) + text + this.value.substring(endPos, this.value.length); this.selectionStart = startPos + text.length; this.selectionEnd = startPos + text.length; } else { this.value += text; }   };//insertatcaret $('body').on('keydown.tab2spaces', 'textarea', function (e) {       var $this = $(this);        switch (e.keyCode) {            case 9:                $this.focus;                $this.get(0).insertAtCaret('    ');                return false;        }    });//txt keydown };