Вот мое решение по данному проекту:
function replace_links() {
var regexp = /(https?:\/\/\S*)|(www\.\S*)|(\S+\.(ru|net|com|kr|jp)\S*)/ig
var replacer = function(t) {
var _t = t;
if(!/https?:\/\//.test(t))
t = 'http://' + t;
return '<a href="' + t + '" target="_blank">' + _t + '</a>';
};
var all_tags = document.getElementsByTagName('*');
var replaced_elems = [];
for(var i = 0; i < all_tags.length; i++) {
//exit on <script> and <a> before recursive
var tmp = all_tags[i]; var exit = false;
while('HTML' != tmp.tagName) {
if('A' == tmp.tagName || 'SCRIPT' == tmp.tagName || 'STYLE' == tmp.tagName) {
exit = true;
break;
}
tmp = tmp.parentNode;
}
if(exit) {
continue;
}
//cycle for Text Nodes in current Tag
for(var j = 0; j < all_tags[i].childNodes.length; j++) {
if(3 == all_tags[i].childNodes[j].nodeType) {
var str = all_tags[i].childNodes[j].nodeValue;
regexp.lastIndex = 0;
if(regexp.test(str)){
str = str.replace(regexp, replacer);
replaced_elems.push([all_tags[i].childNodes[j], str]);
}
}
}
}
for(var i = 0; i < replaced_elems.length; i++) {
var curr_elem = replaced_elems[i][0];
var str = replaced_elems[i][1];
curr_elem.nodeValue = '';
var tmp_elem = document.createElement('div');
tmp_elem.innerHTML = str;
for(var j = 0, s = tmp_elem.childNodes.length; j < s; j++) {
curr_elem.parentNode.insertBefore(tmp_elem.childNodes[0], curr_elem);
}
}
}