Skip to content

Instantly share code, notes, and snippets.

/url_replace.js Secret

Created December 6, 2011 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/650b3226131a7c1db493 to your computer and use it in GitHub Desktop.
Save anonymous/650b3226131a7c1db493 to your computer and use it in GitHub Desktop.
URL Replacement for BACKPACKINGLIGHT.COM forums
<script type="text/javascript" async defer>
$(function(){
var regex = /\b(([\w-]+:\/\/?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|)))/gi;
$("td.body").each(function(i, elem){
var $elem = $(elem);
var html = $elem.html();
$elem.html(html.replace(regex, function(str){
var index = html.indexOf(str, 0);
if (html[index - 1] != '"') { // make sure it's not already a link
return "<a href='" + str + "'>" + str + "</a>";
} else {
return str;
}
}));
});
})</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment