User:Pirr/global.js

'use strict'; // Get MediaWiki configuration options for current site var conf = mw.config.get( [       'wgContentLanguage',        'wgUserLanguage',        'wgUserGroups',        'wgUserName',        'wgScriptPath',        'wgVersion',        'wgNamespaceNumber'    ] ); // Prevent double loading aaaand pls don't blow up in my face when they finally update MW   if ( window.htzo7tpmw6ha6qo || conf.wgVersion !== '1.19.24' ) return; // Check my user groups self.groups = /sysop|bureaucrat|content-moderator|threadmoderator/.test( conf.wgUserGroups.join ); /**    * Replacement for `jQuery.fn.extend` method * https://stackoverflow.com/a/38777298 *    * @param defaults * @param options */   function extend( defaults, options ) { var prop, extended = {}; for ( prop in defaults ) { if ( Object.prototype.hasOwnProperty.call( defaults, prop ) ) extended[prop] = defaults[prop]; }       for ( prop in options ) { if ( Object.prototype.hasOwnProperty.call( options, prop ) ) extended[prop] = options[prop]; }       return extended; }   /**     * Simple i18n implementation *    * @param msg * @param lang */   function i18n( msg, lang ) { var a;       // Check if language is specified. If so, check if it's content. Use current user language by default if ( lang ) { a = ( lang === 'content' ? conf.wgContentLanguage : lang ); } else { a = conf.wgUserLanguage; }       // i18n messages var string = { en: { // English (en) 'recentchanges': 'Recent changes', 'summary-delete': 'Housekeeping', 'summary-block': 'Vandalism', 'summary-comment': 'Harmful comment', 'analytics': 'Analytics', 'announcements': 'Announcements' },           pl: { // polski (pl) 'recentchanges': 'Ostatnie zmiany', 'summary-delete': 'Porządki', 'summary-block': 'Wandalizm', 'summary-comment': 'Obraźliwy komentarz', 'analytics': 'Dane analityczne', 'announcements': 'Ogłoszenia' }       };        // Use English as fallback language string = extend( string.en, string[a] ); // Return wanted message return string[msg]; }   /**     * Import my custom user scripts - regular user or both user and admin codes *    * @param scripts */   self.importScripts = function( scripts ) { // Prepare array for merging var array = {}; // Check for groups and merge arrays if I'm sysop if ( self.groups ) { array = scripts.user.concat( scripts.admin ); } else { // Or leave it as it is if I'm not array = scripts.user; }       // Import scripts specified in function call importArticles( {           type: 'script',            articles: array        } ); };   // Other small snippets to use on page self.snippets = function { // Prevent annoying RaiLWAM module from being loaded if ( !window.hasOwnProperty( 'railWAM' ) ) window.railWAM = {}; if ( !window.railWAM.hasOwnProperty( 'load' ) ) window.railWAM.load = false; // ... or remove it if loaded already var WAMlogs = document.getElementById( 'railwam-rail-mod' ); if ( WAMlogs ) WAMlogs.remove; // Force source editor on template pages (damn you, InfoboxBuilder!) var editButton = document.getElementById( 'ca-edit' ); if ( conf.wgNamespaceNumber === 10 && editButton ) editButton.href += '&useeditor=source'; // Add my custom links in toolbar var userToolbar = document.getElementById( 'my-tools-menu' ); if ( userToolbar && self.groups ) { var li1 = document.createElement( 'li' ), li2 = document.createElement( 'li' ); li1.classList.add( 'overflow' ); li1.id = 'custom-tool1'; li2.classList.add( 'overflow' ); li2.id = 'custom-tool2'; var announcements = document.createElement( 'a' ), analytics = document.createElement( 'a' ); announcements.href = conf.wgScriptPath + '/announcements'; announcements.innerText = i18n( 'announcements' ); analytics.href = mw.util.getUrl( 'Special:Analytics' ); analytics.innerText = i18n( 'analytics' ); userToolbar.appendChild( li1 ); userToolbar.appendChild( li2 ); document.getElementById( 'custom-tool1' ).appendChild( announcements ); document.getElementById( 'custom-tool2' ).appendChild( analytics ); }       // Change "WikiActivity" link's direction var activityLink = document.querySelector( '.wds-community-header__wiki-buttons a[data-tracking="wiki-activity"]' ); if ( activityLink ) { activityLink.href = mw.util.getUrl( 'Special:Recentchanges' ); activityLink.title = i18n( 'recentchanges' ); }       // Open all external links in new window var externalLinks = document.querySelectorAll( 'a.external' ); if ( externalLinks ) externalLinks.forEach( function( link ) {           link.target = '_blank';        } ); // Replace default deletion reason var deleteReason = document.querySelector( '#mw-delete-table #wpReason' ); if ( deleteReason ) deleteReason.value = i18n( 'summary-delete', 'content' ); // Uncheck "Leave redirect behind" checkbox var leaveRedirect = document.getElementById( 'wpLeaveRedirect' ); if ( leaveRedirect ) leaveRedirect.checked = false; };   // Initialize this script self.init = function { // Add other scripts' configuration options window.ajaxSpecialPages = [ 'Recentchanges', 'Images', 'Videos', 'Watchlist', 'Newwikis', 'Log', 'Newpages', 'Wikiactivity', 'Brokenredirects', 'Doubleredirects' ];       window.ajaxRefresh = 15000; window.MultiUploadoption = { max: 75 }; window.lastEdited = { avatar: false }; window.qtUserPageTemplate = '' : '}}'; window.WHAMDeleteReason = i18n( 'summary-delete', 'content' ); window.WHAMBlockReason = i18n( 'summary-block', 'content' ); window.AjaxCommentDeleteConfig = i18n( 'summary-comment', 'content' ); // Perform import action self.importScripts( {           user: [                'u:dev:MediaWiki:ConsistentNotifications.js',                'u:dev:MediaWiki:AjaxUndo/code.js',                'u:dev:MediaWiki:AjaxRC/code.js',                'u:dev:MediaWiki:NullEditButton/code.js',                'u:dev:MediaWiki:MultiUpload/code.js',                'u:dev:MediaWiki:RevealAnonIP/usercode.js',                'u:dev:MediaWiki:UnhideUserMasthead/code.js',                'u:dev:MediaWiki:View Source/code.js',                'u:dev:MediaWiki:LastEdited/code.js',                'u:dev:MediaWiki:QuickCreateUserPage/code.js',                'u:dev:MediaWiki:FindAndReplace/code.js',                'u:dev:MediaWiki:UserAndIPTools.js',                'u:dev:MediaWiki:TVMH.js'            ],            admin: [                'u:dev:MediaWiki:WHAM/code.2.js',                'u:dev:MediaWiki:AjaxBatchDelete.js',                'u:dev:MediaWiki:AjaxPatrol/code.js', 'u:dev:MediaWiki:AjaxCommentDelete/code.js', 'u:dev:MediaWiki:CategoryRenameAuto-update/code.js', 'u:dev:MediaWiki:FileUsageAuto-update/code.js', 'u:dev:MediaWiki:ViewRemoved/code.js' ]       } );        // Run snippets        self.snippets;        window.htzo7tpmw6ha6qo = true;    };    // Make the foxy magic happen!    self.init; } )( mediaWiki, this, {} );
 * ( function( mw, window, self ) {