User:Majr/hydra.js

$( function { 'use strict';

var baseURL = '/', wikiURL = '/wiki/', $grids = $( '.grid2' ), imgString = ''; if ( $grids.length ) { $grids.each( function {       var imgs = $( this ).data( 'imgs' );        if ( !imgs ) {            return true;        }        imgs = imgs.split( ';' );        imgs.shift;        $.each( imgs, function { if ( this.indexOf( ':' ) > -1 ) { this.replace( /([^:]*):?([^,]*)/, function( $, mod, name ) {                   if ( imgString.indexOf( 'File:Grid ' + name.trim + ' (' + mod.trim + ').png' ) === -1 ) {                        imgString += 'File:Grid ' + name.trim + ' (' + mod.trim + ').png|';                    }                } ); } else { this.replace( /([^,]*)/, function( $, name ) {                   if ( imgString.indexOf( 'File:Grid ' + name.trim + '.png' ) === -1 ) {                        imgString += 'File:Grid ' + name.trim + '.png|';                    }                } ); }       } );    } );    imgString = imgString.slice( 0, -1 );

/* Thanks to an API bug, &redirects doesn't work properly with prop=imageinfo * Some of the images will return without any imageinfo, even though they are valid * So the redirects have to be resolved in a separate request... */   if ( imgString ) { $.ajax( {           type: 'POST',            url: baseURL + 'api.php?action=query&format=json&redirects',            data: { titles: imgString },            timeout: 20000        } ).done( function( data ) {            var redirects = {};            $.each( data.query.redirects, function { redirects[this.to] = this.from; imgString = imgString.replace( this.from, this.to ); } );           $.ajax( { type: 'POST', url: baseURL + 'api.php?action=query&format=json&prop=imageinfo&iiprop=url&iiurlwidth=32&iiurlheight=32', data: { titles: imgString }, timeout: 20000 } ).done( function( data ) { var urls = {}; $.each( data.query.pages, function( index ) {                   if ( index < 0 ) {                        return true;                    }                    if ( redirects.hasOwnProperty( this.title ) ) {                        urls = this.imageinfo[0].thumburl;                    } else {                        urls = this.imageinfo[0].thumburl;                    }                } ); $grids.each( function {                   var $grid = $( this ), imgs = $grid.data( 'imgs' ), html = '';                    if ( !imgs ) {                        return true;                    }                    imgs = imgs.split( ';' );                    imgs.shift;                    $.each( imgs, function { if ( this.indexOf( ':' ) > -1 ) { this.replace( /([^:]*):?([^,]*),?(\d*)/, function( $, mod, name, num ) {                               name = name.trim + ' (' + mod.trim + ')';                                html += gridFormat( name, urls[name], num );                            } ); } else { this.replace( /([^,]*),?(\d*)/, function( $, name, num ) {                               html += gridFormat( name.trim, urls[name.trim], num );                            } ); }                   } );                    $grid.find( '> .border > span > .animated' ).append( html );                } ); } ).fail( function( error ) { console.error( error ); } );       } ).fail( function( error ) {            console.error( error );        } ); } }

function gridFormat( name, url, num ) { var html = ' '; if ( url ) { html += ''; if ( num ) { html += ' ' + num + ' '; }   } else { html += ''; }   return html += ' '; }

} );

// Uses AJAX for previewing and showing changes - Original script: wikipedia:User:Js/ajaxPreview.js if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) { importScript( 'User:Ultradude25/ajaxPreview.js' ); }

// Counts all your edits and saves them to a page - Original script: if ( mw.config.get( 'wgTitle' ) === mw.config.get( 'wgUserName' ) && mw.config.get( 'wgNamespaceNumber' ) === 2) { importScript( 'User:Ultradude25/editcounter.js' ); }

// Adds JavaScript and CSS syntax highlighting - Original script: importScript( 'User:Ultradude25/syntaxHighlight.js' ); importScript( 'User:Ultradude25/syntaxHighlight/javascript.js' ); importScript( 'User:Ultradude25/syntaxHighlight/css.js' );

// Adds Doc + Doc discussion tabs to template pages and change Template + Discussion tabs to always link to the original template + discussion page if ( mw.config.get( 'wgNamespaceNumber' ) === 10 || mw.config.get( 'wgNamespaceNumber' ) === 11 ) { importScript( 'User:Ultradude25/docTabs.js' ); }

// Allows rollback summary to be edited importScript( 'User:Ultradude25/editableRollback.js' );

// Parse tweets importScript( 'User:Ultradude25/twitterFeed.js' );

importScript( 'User:Ultradude25/refTooltip.js' );

$( function { 'use strict';

// Adds a history link to the new messages box - Original script: wikipedia:User:Davidgothberg/newmessageshistory.js $( '#mw-youhavenewmessages a:last' ).after( ', history' );

// Changes vector menu items into tabs $( '#p-cactions .menu li' ).addClass( 'collapsible' ); $( '#p-cactions .menu li a' ).wrap( ' ' ); $( '#p-views ul li:last' ).after( $( '#p-cactions .menu li' ) ); $( '#p-cactions' ).addClass( 'emptyPortlet' );

// Replaces ugly links with fancy ones ("/wiki/Pagename?action=edit" instead of "/index.php?title=Pagename&action=edit") $( 'a' ).prop( 'href', function {   return this.href.replace( /\/index\.php\?title=([\w:/=!\-.\(\)]*)&(?!action=(?:un)?watch)([\w:/=]*)/, "/wiki/$1?$2" ); } );

} );