User:Seb35/vector.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*
document.write('<s'+'cript type="text/javascript" src="//fr.wikipedia.org/w/index.php?title=Utilisateur:Seb35/common.js&amp;action=raw&amp;ctype=text/javascript" />');

adSearchProject='wikipedia.org';
adSearchLang0='';   
adSearchLang0project='meta.wikimedia.org';      
adSearchLang0name='m';
adSearchLang1='fr'; 
adSearchLang1project='wikipedia.org';           
adSearchLang1name='fr';
adSearchLang2='';   
adSearchLang2project='wikimediafoundation.org'; 
adSearchLang2name='f';
*/

// Harmonize the 'edit' et 'translate' buttons on the translation pages
if( $('.mw-translate-page-info').length || $('.mw-pt-translate-header').length ) {
  
    addOnloadHook( function() {
        
        // Remove 
        $('#mw-content-text hr:eq(0)').remove();
        
        // A translation        
        if( mw.config.get('wgPageContentLanguage') !== mw.config.get('wgContentLanguage') ) 
        { 
            mw.util.addPortletLink( 'p-cactions', mw.util.getUrl(null,{'action':'edit'}), 'Voir le texte source' );
        
        } // Original (in English)
        else if( $('.mw-pt-translate-header').length > 0 ) 
        { 
            mw.util.addPortletLink( 'p-views', 
                                    $('.mw-pt-translate-header a:eq(0)').attr('href'), 
                                    'Traduire', 
                                    'ca-translate', 
                                    '[['+mw.config.get('wgPageName').replace(/_/g,' ')+']] — '+$('.mw-pt-translate-header a:eq(0)').attr('href').replace(/^.*language=([a-z-]*).*$/,'$1'), 
                                    null, 
                                    $('#ca-history') );
        
        }
   
        // remove the translation header
        if( $('.mw-pt-translate-header a').length == 1 ) {
            $('.mw-pt-translate-header').remove();
        }                        
    });
}

// purge button
// partially copied from https://www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&oldid=3985357
mw.loader.using( ['mediawiki.util', 'mediawiki.api'] ).then( function () {
  $( function() {
    var node = mw.util.addPortletLink( 'p-cactions', mw.util.getUrl(null,{'action':'purge'}), 'Purger', 'ca-purge' );
    if( !node ) { return; }
    $( node ).on( 'click', function ( e ) {
      new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then( function () {
        location.reload();
      }, function () {
        mw.notify( 'Purge failed', { type: 'error' } );
      } );
      e.preventDefault();
    } );
  } );
} );