My current task involves making a slight adjustment to a script. The modification should make the script prompt for the text to search for, followed by the replacement text. Once all processing is complete, a dialog box will notify me that it's finished.
I intend to implement this on a phpmyadmin database edit page where there will be numerous textboxes filled with content (which requires searching and replacing). The search and replace texts may span multiple lines, hence I have included the 'm' parameter in the regex. Additionally, since some searches or replacements may contain HTML with quotes or double quotes, I need to account for those as well. For example:
Search for:
<img height="76" width="92" src="http://www.gifs.net/Animation11/Hobbies_and_Entertainment/Games_and_Gambling/Slot_machine.gif" /></div>
<div class="rtecenter"> <strong><em><font color="#ff0000">Vegas Baby!<br />
</font></em></strong></div>
It may be replaced with nothing (to remove the code entirely) or with other HTML. Here is the bookmarklet I have developed so far (I am not very familiar with JavaScript and bookmarklets), although it is not yet functioning in terms of finding and replacing, despite correct prompting:
javascript:var%20scrEl=document.createElement('script');scrEl.setAttribute('language','javascript');scrEl.setAttribute('type','text/javascript');scrEl.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js');function%20htmlreplace(a,b,element){if(!element)element=document.body;var%20nodes=$(element).contents().each(function(){if(this.nodeType==Node.TEXT_NODE){var%20r=new%20RegExp(a,'gim');this.textContent=this.textContent.replace(r,b);}else{htmlreplace(a,b,this);alert('Done%20processing.');}});}htmlreplace(prompt('Text%20to%20find:',''),prompt('Replace%20with:',''));
If anyone has any suggestions or ideas, please share!