Jump to content

User:Frietjes/replace.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Frietjes (talk | contribs) at 23:58, 6 March 2018. The present address (URL) is a permanent link to this version.
(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.
jQuery(document).ready(function($) {
	
if(mw.config.get('wgNamespaceNumber') != -1) {
	mw.loader.using(['mediawiki.util']).done( function() {
		var portletlink = mw.util.addPortletLink('p-tb','#','Search/replace','t-search-replace');
		$(portletlink).click(function(e) {
			e.preventDefault();
			wpTextboxReplace();
		});
	});
}

function wpTextboxReplace()
{
 var s = prompt("Search regexp:");
 if(s){
  var r = prompt("Replace /"+s+"/ with:");
  if(!r && r !== '') return;
  r = r.replace(/\\n/g, '\n');
  r = r.replace(/\\t/g, "\t");
  var txt = document.editform.wpTextbox1;
  txt.value = txt.value.replace(new RegExp(s, "mg"), r);
 }
}

});