Skip to content

Instantly share code, notes, and snippets.

@roytam1
Created December 16, 2016 08:44
Show Gist options
  • Save roytam1/84e842993987fdd16b2f806d4c4be398 to your computer and use it in GitHub Desktop.
Save roytam1/84e842993987fdd16b2f806d4c4be398 to your computer and use it in GitHub Desktop.
textarea URL to HTML
javascript:void%20function(){function%20t(t){var%20e=/[^%3C%3E]\b(%3F:https%3F|ftp):\/\/[a-z0-9-+%26%40%23\/%25%3F=~_|!:,.;]*[a-z0-9-+%26%40%23\/%25=~_|](%3F![^%3C%3E])/gim;return%20t.replace(e,'%3Ca%20href=%22$%26%22%3E$%26%3C/a%3E')}function%20e(a){a||(a=document.body);for(var%20n=a.childNodes,o=0;o%3Cn.length;o++)3==n[o].nodeType||(%22textarea%22==(x=n[o].tagName.toLowerCase())||%22input%22==x%26%26%22text%22==n[o].getAttribute(%22type%22)%3Fn[o].value=t(n[o].value):e(n[o]))}function%20a(t){try{e(t.document.body);for(var%20n=0;n%3Ct.frames.length;n++)a(t.frames[n])}catch(o){}}a(window)}();
/*
Maillist URL replacer
Use http://rthost.cf/Bookmarkleter.htm or http://chriszarate.github.io/bookmarkleter/ to create bookmarklet
*/
function repl(text) {
var exp = /[^<>]\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|](?![^<>])/gim;
return text.replace(exp, '<a href="$&">$&</a>');
}
function htmlreplace(element) {
if (!element) element = document.body;
var nodes = element.childNodes;
for (var n=0; n<nodes.length; n++) {
if (nodes[n].nodeType == 3) { //Node.TEXT_NODE == 3
// do nothing
} else if ((x = nodes[n].tagName.toLowerCase()) == "textarea" || (x == "input" && nodes[n].getAttribute("type") == "text")) {
nodes[n].value=repl(nodes[n].value);
} else {
htmlreplace(nodes[n]);
}
}
}
function traverse(w){
try{
/* Manipulate w.document */
htmlreplace(w.document.body);
for(var i=0; i<w.frames.length; i++)
traverse(w.frames[i]);
}
catch(e){
/* Do something with e or just do nothing */
}
}
traverse(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment