User:Griffinofwales/hide-images.js

From Simple English Wikipedia, the free encyclopedia

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.
( function ( mw, $ ){
    var hide_regex = /^(?:https?:)?\/\/upload.wikimedia.org\/wikipedia\/(?:en|commons)\//;

    function clickHandler ( e ) {
        e.stopPropagation();
        e.preventDefault();
        $( this.firstChild ).unwrap();
    };

    function makeWrapper () {
        return $( '<span>', {
            'class': 'hide-images-wrapper',
            'click': clickHandler
        } );
    };

    $( 'img' ).each( function () {
        if ( hide_regex.test( this.src ) ) {
            $( this ).wrap( makeWrapper );
        }
        $( this ).addClass( 'hide-images-handled' );
    } );
}( mediaWiki, jQuery ) );