CodeWrite Bookmarklet

It is a bookmarklet that makes the code written in textarea HTML entity.
"<" and ">" are converted into "&lt" and "&gt".
The character string under the selection of textarea is made an entity. When not selecting it at all, the whole is made an entity.

Source (red-treasure.com)


Download Bookmarklet:


View Bookmarklet Code:

Bookmarklet Source Code:

javascript%3A%28function%28%29%7Bcodewrite%28%29%3Bfunction%2520enentity%28content%29%7B%2520return%2520content.replace%28/%26/g%2C%27%26amp%3B%27%29.replace%28/%22/g%2C%27%26quot%3B%27%29.replace%28/%3C/g%2C%2520%27%26lt%3B%27%29.replace%28/%3E/g%2C%2520%27%26gt%3B%27%29.replace%28/%2520/g%2C%27%26nbsp%3B%27%29.replace%28/%5Ct/g%2C%27%26nbsp%3B%26nbsp%3B%26nbsp%3B%27%29%3B%7Dfunction%2520codewrite%28%29%7B%2520var%2520mm%2520%3D%2520document.getElementsByTagName%28%27TEXTAREA%27%29%3B%2520var%2520m%3B%2520%2520for%28var%2520i%2520%3D%25200%3B%2520i%2520%3C%2520mm.length%3B%2520i++%29%7B%2520m%2520%3D%2520mm%5Bi%5D%3B%2520if%28document.selection%29%7B%2520m.focus%28%29%3B%2520sel%2520%3D%2520document.selection.createRange%28%29%3B%2520if%28sel.text.length%2520%3E%25200%29%7B%2520sel.text%2520%3D%2520enentity%28sel.text%29%3B%2520%7D%2520else%2520%7B%2520continue%3B%2520%7D%2520%2520m.focus%28%29%3B%2520%7D%2520else%2520if%28m.selectionStart%2520%7C%7C%2520m.selectionStart%2520%3D%3D%2520%270%27%29%7B%2520var%2520startPos%2520%3D%2520m.selectionStart%3B%2520var%2520endPos%2520%3D%2520m.selectionEnd%3B%2520var%2520cursorPos%2520%3D%2520endPos%3B%2520var%2520scrollTop%2520%3D%2520m.scrollTop%3B%2520if%28startPos%2520%21%3D%2520endPos%29%7B%2520var%2520before%2520%3D%2520m.value.substring%28startPos%2C%2520endPos%29%3B%2520var%2520after%2520%3D%2520enentity%28before%29%3B%2520m.value%2520%3D%2520m.value.substring%280%2C%2520startPos%29+%2520after%2520+%2520m.value.substring%28endPos%2C%2520m.value.length%29%3B%2520cursorPos%2520+%3D%2520after.length%2520-%2520before.length%3B%2520%7D%2520else%2520%7B%2520continue%3B%2520%7D%2520%2520m.focus%28%29%3B%2520m.selectionStart%2520%3D%2520cursorPos%3B%2520m.selectionEnd%2520%3D%2520cursorPos%3B%2520m.scrollTop%2520%3D%2520scrollTop%3B%2520%7D%7D%7D%7D%29%28%29%3B


Rate it:


Tags:

Comments

Comments so far. Add yours.

mikami

"<" and ">" are converted into "&lt and "&gt".


mikami

&quot;&lt;&quot;&nbsp;and&nbsp;&quot;&gt;&quot;&nbsp;are&nbsp;converted&nbsp;into&nbsp;&quot;&amp;lt;&quot;&nbsp;and&nbsp;&quot;&amp;gt;&quot;.&nbsp;

(I should have used "CodeWrite"......)


KANALLA

MAMA


www.thegeniusfiles.com

Nice bookmarklet, but I find that it only works when you select the text. It does not work if text is not selected. Still, very handy!


mikami

sorry. This bookmarklet requires the range selection of the text.
I seem to have been misunderstanding it.