I used a bookmarklet editor to create them, then dragged the editor generated links on to my bookmark bar. To use them, I highlight the appropriate part of a textarea and click Escape or Unescape on the bookmark bar.
Here's Escape:
javascript:
(function(){
var textareas=document.getElementsByTagName('textarea');
for(var i=textareas.length-1;i>=0;i--){
textarea=textareas[i];
var start=textarea.selectionStart;
var end=textarea.selectionEnd;
var prefix=textarea.value.substring(0,start);
var text=textarea.value.substring(start,end);
var suffix=textarea.value.substring(end,textarea.value.length);
text=text.replace(/&/g,'&');
text=text.replace(/</g,'<');
text=text.replace(/>/g,'>');
text=text.replace(/"/g,'"');
textarea.value=prefix+text+suffix;
}
}
)()
Here's Unescape:
To add these as links you need to perform the following substitutions:
javascript:
(function(){
var textareas=document.getElementsByTagName('textarea');
for(var i=textareas.length-1;i>=0;i--){
textarea=textareas[i];
var start=textarea.selectionStart;
var end=textarea.selectionEnd;
var prefix=textarea.value.substring(0,start);
var text=textarea.value.substring(start,end);
var suffix=textarea.value.substring(end,textarea.value.length);
text=text.replace(/</g,'<');
text=text.replace(/>/g,'>');
text=text.replace(/"/g,'"');
text=text.replace(/&/g,'&');
textarea.value=prefix+text+suffix;
}
}
)()
s/ /%20/g;s/'/%27/g;s/"/%22/gs;s/&/%26/g;s/</%3c/g;s/>/%3e/g
By the way, if anyone knows how to identify in a bookmarklet which <textarea> in an HTML page has the focus, please let me know!
No comments:
Post a Comment