Utilisateur:Framawiki/spamblock.js

De Anekdotos

Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

  • Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
  • Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
  • Internet Explorer / Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
  • Opera : appuyez sur Ctrl + F5.
// Importé de [[:w:fr:Utilisateur:0x010C/script/SpamBlock.js]]
// (c) fantastique 0x010C

// Ajouter dans son common.js mw.loader.load( "https://anekdotos.net/index.php?title=Utilisateur:Framawiki/spamblock.js&action=raw&ctype=text/javascript");
// et aller sur https://anekdotos.net/index.php?title=Sp%C3%A9cial:Journal&offset=&limit=500&type=newusers&useskin=vector&user=

mw.loader.load('mediawiki.api');
mw.loader.load('mediawiki.util');


function block( username ) {
  var api = new mw.Api();
  return api.postWithToken( 'csrf', {
    action: 'block',
    user: username,
    expiry: 'never',
    reason: 'spam',
    nocreate: '1',
    autoblock: '1',
    noemail: '1',
    tags: 'spamblock'
  } );
}

function spamblock() {
  $( '.mw-logline-newusers' ).each( function() {
    if ( $( this ).find( ':checked' ).length ) {
      var self = this;
      block( $( this ).find( 'a.new.mw-userlink' ).text() )
      .then( function( data ) {
        console.log( data.block.id );
        $( self ).css( 'background', '#b1f968' );
        $( self ).append( $( '<i>' ).html( '<small>Blocage #' + data.block.id + '</small>' ) );
      } )
      .fail( function( data ) {
        if ( data === 'alreadyblocked' ) {
          $( self ).css( 'background', '#f9f968' );
        }
        else {
          alert('failed');
          alert(data);
          $( self ).css( 'background', '#fc4c49' );
        }
      } );
    }
  } );
}

if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Log' && mw.util.getParamValue( 'type' ) === 'newusers' ) {
  var button = $( '<button>' ).text( 'Bloquer en masse des comptes créé en rafale' );
  button.click( function( e ) {
    e.preventDefault();
    spamblock();
  } );
  $( '.mw-checkbox-toggle-controls' ).eq( 0 ).before( button );
}