Jump to content

User:Mr. Stradivarius/chessboardfix.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 04:55, 27 October 2014 (test getting currently highlighted text). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var myContent = document.getElementsByName('wpTextbox1')[0];

function replaceSelection(replace) {
	// Replace currently selected text with the string s.
	var len = myContent.value.length;
	var start = myContent.selectionStart;
	var end = myContent.selectionEnd;
	var sel = myContent.value.substring(start, end);

	if ( typeof( replace ) == 'function' ) {
		replace = replace( sel );
	}

	myContent.value = textarea.value.substring(0, start) + replace + textarea.value.substring(end, len);
}

function wpChessboardFix() {
	replaceSelection( 'foo' );
}

function TTscriptButton() {
  addPortletLink('p-tb','javascript:wpChessboardFix()','Fix chessboards','t-chessboardfix');
}

if (wgNamespaceNumber != -1 && myContent) {
	addOnloadHook(TTscriptButton);
}