MediaWiki:Gadget-Clipboard.js

/** * Code to manage the content of the clipboard * Created by Ciencia Al Poder on wikidex.net **/ (function( $, document ) {	var _notice = 'This content comes from the Independent Fallout Wiki (https://fallout.wiki), and must be attributed to its authors, as specified in the license. Do not copy any part without giving credit.',	_init = function {		if ( mw.config.get( 'wgUserGroups', [] ).length < 1 ) {			$( '#mw-content-text' ).on( 'cut copy', _copyevent );			$( document.body ).on( 'paste', '[contenteditable],input,textarea', _pasteevent );		}	},	_copyevent = function( e ) {		var text, $target;		$target = $( e.target );		if ( $target.closest( '.ace_editor' ).length > 0 ) {			return;		} else if ( $target.is( 'input,textarea' ) ) {			if ( e.type == 'cut' ) {				return;			}			text = $target.val.substring( e.target.selectionStart, e.target.selectionEnd );		} else {			text = document.getSelection.toString;		}		if ( text.length < 40 ) {			return;		}		text = text + _notice;		( e.originalEvent.clipboardData || window.clipboardData ).setData( 'text/plain', text ); e.preventDefault; console.log( 'Content to be copied modified. Report any problems to Vish.' ); },	_pasteevent = function( e ) { var paste, selection, input, startPos, endPos, text; paste = ( e.originalEvent.clipboardData || window.clipboardData ).getData( 'text/plain' ); if ( paste.indexOf( _notice ) == -1 ) { return; }		paste = paste.replace( _notice, ''); if ( $( event.target ).is( '[contenteditable]' ) ) { selection = window.getSelection; if ( !selection.rangeCount ) { return false; }			selection.deleteFromDocument; selection.getRangeAt( 0 ).insertNode( document.createTextNode( paste ) ); } else { input = event.target; if ( input.selectionStart !== undefined ) { startPos = input.selectionStart; endPos = input.selectionEnd; text = $( input ).val; text = text.substring( 0, startPos ) + paste + text.substring( endPos ); $( input ).val( text ); endPos = startPos + paste.length; input.setSelectionRange( endPos, endPos ); }		}		console.log( 'Content to paste modified.' ); e.preventDefault; };	$( _init ); })( jQuery, document );