User:Isarra/global.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.
popupStructure = 'menus';

/* Rollback all */
$( function() {
	if ( $( 'span.mw-rollback-link' )[0] && mw.config.get( 'wgCanonicalSpecialPageName' ) == 'Contributions' ) {
		mw.util.addPortletLink( 'p-cactions', 'javascript:rollbackEverything()', "rollback all", "ca-rollbackeverything", "Rollback all top edits displayed here" );
	}
} );

function rollbackEverything() {
	for ( var i in document.links ) {
		if ( document.links[i].href.indexOf( 'action=rollback' ) != -1 )
			window.open( document.links[i].href+'&bot=1' );
	}
}

$( function(){ 
	if( mw.config.get( 'wgNamespaceNumber' ) > -1 ) {  
 		mw.util.addPortletLink( 'p-cactions', '/wiki/Special:PrefixIndex/' + mw.config.get( 'wgPageName' ), 'Subpages', 'd-subpages', 'List subpages and other pages starting with this title' ); 
	}
} );

/* Tab thing like proper (yoinked from SO) */
$( 'textarea' ).keydown( function( e ) {
	if( e.keyCode === 9 ) { // tab was pressed
		// get caret position/selection
		var start = this.selectionStart;
		var end = this.selectionEnd;

		var $this = $( this );
		var value = $this.val();

		// set textarea value to: text before caret + tab + text after caret
		$this.val( value.substring( 0, start )
			+ "\t"
			+ value.substring( end ) );

		// put caret at right position again (add one for the tab)
		this.selectionStart = this.selectionEnd = start + 1;

		// prevent the focus lose
		e.preventDefault();
	}
} );