User:Cafeinlove/global.js

importArticles({   type: 'script',    articles: [        // add purge button        'u:dev:MediaWiki:PurgeButton/code.js',    ] }); /** * My utility scripts. * Feel free to copy-pasta for your own personal use. * * @author User:Cafeinlove * @license Public Domain */ (function($, mw) {   // MediaWiki states    var config = mw.config.get([ 'wgContentLanguage', 'wgServer', 'wgUserName', 'wgUserLanguage' ]);   // Utility functions    var util = {        getHostURL: function {            return [                config.wgServer,                config.wgContentLanguage,                'wiki',                ''            ].join('/');        },        // select text within passed element        selectText: function(element) {    		var range = document.createRange;    		var selection = window.getSelection;    		range.selectNodeContents(element);    		selection.removeAllRanges;    		selection.addRange(range);    	}    };    // Add `My sandbox` to account dropdown menu.    (function { var i18n = { ko: { name: '내 연습장', link: '/연습장' },           en: { name: 'My sandbox', link: '/sandbox' }       };        var settings = { menuIndex: 3 };       // environment DOM var $nav = $('#globalNavigation'); var $menu = $nav .find('.wds-global-navigation__user-menu') .find('.wds-dropdown__content'); var $position = $menu.find('li:eq(' + settings.menuIndex + ')') // created DOM var pageURL = util.getHostURL + 'User:' + config.wgUserName + i18n[config.wgContentLanguage].link; var pageName = i18n[config.wgUserLanguage].name; var $li = $(' '); var $a = $('', { href: pageURL }).text(pageName); $li.append($a).insertBefore($position); });   // Select whole text content blocks by double clicking.    // Works with specific pre-defined tags like, or so.    (function { var tagNames = ['code', 'pre', 'samp', 'var']; var tagPattern = new RegExp('^' + tagNames.join('|') + '$'); $(document).dblclick(function(event) {           var clicked = event.target;            var clickedTag = clicked.tagName.toLowerCase;            var isTarget = tagPattern.test(clickedTag);            if (isTarget) {                util.selectText(clicked);            }        }); }); })(jQuery, window.mediaWiki);