EditorReplace.js

//
$("body").append(
	'<section id="findandreplace">\n' +
		'\t<img id="findandreplace-close" src="http://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Emblem-unreadable.svg/14px-Emblem-unreadable.svg.png" onclick="this.parentNode.style.display=\'none\'"/>\n' +
		'\tFind what:\n' +
		'\t<textarea id="findandreplace-f"></textarea>\n' +
		'\tReplace with:\n' +
		'\t<textarea id="findandreplace-r"></textarea>\n' +
		'\t\n' +
		'\t<input type="button" class="wikia-button" id="findandreplace-go" value="go" />\n' +
		'\t<input type="checkbox" id="findandreplace-case" /><label for="findandreplace-case">Match case</label>\n' +
		'\t<input type="checkbox" id="findandreplace-regex" /><label for="findandreplace-regex">Regexs</label>\n' +
		'\t<button class="wikia-button explain" id="findandreplace-history-trigger" title="The data will be inserted to your console">hist</button>\n' +
		'\t<input type="hidden" id="findandreplace-history" />\n' +
	'</section>'
);
mw.util.addCSS(
	'section#findandreplace {\n' +
		'\tdisplay: none;\n' +
		'\twidth: 400px;\n' +
		'\tposition: fixed;\n' +
		'\ttop: 300px;\n' +
		'\tleft: ' + (($(window).width() - 312)/ 2) + 'px;\n' +
		'\tz-index: 100;\n' +
		'\tpadding: 5px;\n' +
		'\tbackground: #fafafa;\n' +
		'\tborder: 1px solid #ccc;\n' +
		'\tcolor: #333;\n' +
	'}' +
	'section#findandreplace textarea {\n' +
		'\twidth: 392px;\n' +
		'\tmargin: 0;\n' +
		'\tpadding: 3px;\n' +
		'\tresize: none;\n' +
	'}' +
	'section#findandreplace #findandreplace-close {\n' +
		'\tfloat: right;\n' +
		'\tcursor: hand;\n' +
		'\tcursor: pointer;\n' +
	'}'
);
$("section#findandreplace #findandreplace-history").data({
	hist: [],
	current: 0,
	nonidenticals: 0,
	ts: -1
});
$("section#findandreplace #findandreplace-go").click(function() {
	/*var*/ text = wpTextbox1.value,
		findRaw = $("section#findandreplace #findandreplace-regex:checked").length == 0 ? $("section#findandreplace #findandreplace-f").val().replace(/[\[\]\{\}\\\$\^\-\?\!\.\+\*\=\,\|]/g,"\\$&") : $("section#findandreplace #findandreplace-f").val().replace(/\\/g,"\\\\"),
		find = new RegExp(findRaw, "g" + ($("section#findandreplace #findandreplace-case:checked").length == 0 ? "i" : "")),
		repwith = $("section#findandreplace #findandreplace-r").val().replace(
			/\$/g,
			$("section#findandreplace #findandreplace-regex:checked").length == 0 ? "$$$$" : "$&"
		);
	$("section#findandreplace #findandreplace-history").data().ts = new Date().getTime();
	if ($("section#findandreplace #findandreplace-history").data().hist.indexOf(text) == -1) {
		$("section#findandreplace #findandreplace-history").data().nonidenticals++;
	}
	$("section#findandreplace #findandreplace-history").data().hist.push(text);
	$("section#findandreplace #findandreplace-history").data().current++;
	wpTextbox1.value = text.replace(find,repwith);
});
$("section#findandreplace #findandreplace-history-trigger").click(function() {
	console.info("The property 'hist' contains an array with the history from the oldest to the most recent:");
	console.log($("section#findandreplace #findandreplace-history").data());
});
$(function() {
	var datauri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAWCAYAAAArdgcFAAAABmJLR0QArQC/ANVJT38uAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gYdCCYDnRcuOwAAAjZJREFUOMu1VEFrE0EU/l6dGCUETZQK4kkUBEXoIRjwYioUAnqw4iH0UBCx+BtyEDyLHjWgBZFaUBJRC4EqJFAKlnhpoZBCD54s2toaNcE0O/M8bGYyu1m7FzOwfG++9703b2feDDEzYwDj7sPnEJ+3ewQzg4ig19N2GAZp179sQnSkv3AOsMOwn+u0FcRue9e4FYChLsKywzBIy8wYYgL0B/TQtsMw2EcQjqMGcZ4gZgjH6fQI64D8XOrUIcPV1hueA/Q3AxGBiCCkdDyrMZFBm1uqb+HCmaNYqm9BSsej1dvgiWdAKMWolAp9v5UZnwrkPxQLyIxPdSsEKqUCLl27jeprvzYCqi5vMAAk41G8m32Eq7k7xu2fnz+ZRHV5A4tz07h45abBZDyK7V9tT457D55CSCkBAJs/Wm47KoXvP/94FrCHlBLp7CQW56aRzk7icCxiYu0cRPDuueuQsLnsjVvGzufzkNJBbX4GqbEJfCw/Q2psom/rlHIL7mtFKRUcqcyFK7964vHX5mcwMppDIh7FyGjOnV/Oufpuj0uloADQ24U1ti/wsUQMX3eaWofhRMwkTp87gTcLax6Njvm20zT5hxMx3H/8AlSsrO79KjIDRLieOWuoYmXV8ND3QttdnC2VIaRj77muhax/cbmX71fM3I35t1aj6Zaw5Htjv5aIIBwrOYHAYFA3QNthGKhlhlBqMA8XQBCtVhODGqLR+D2QxPsP7IP4tFL/74kjBwVOHz+CvyW8ZkhZNqmUAAAAAElFTkSuQmCC";
	$('<img src="' + datauri + '" class="mw-toolbar-editbutton" title="Find and Replace" />').click(function() {
			$("section#findandreplace").show();
	}).insertBefore("#cke_toolbar_source_1 .cke_toolbar_expand");
});
//