Jep, det er pænt omstændigt, så det er rart at der er nogle der gider lave det for os :-)
String.prototype.htmlSpaceFix = function() {
var fix = this;
fix = fix.split("> ");
fix = fix.join("> ");
return fix;
};
String.prototype.hotLink = function(linkColor) {
var input = this;
input = "   "+input+" ";
var tex = input.split(" http:");
for (var k = 0; k<tex.length; k++) {
if ((tex[k].substring(0, 5) != "//www") && (tex[k].substring(0, 5) != " ")) {
if (tex[k].indexOf(" ")) {
var index = tex[k].indexOf(" ");
tex[k] = " <u><font color='"+linkColor+"'><a href='http:"+tex[k].substring(0, tex[k].indexOf(" "))+"'>"+"http:"+tex[k].substring(0, tex[k].indexOf(" "))+"</a></font></u>"+tex[k].substring(index);
}
}
}
tex = tex.join("");
tex += " ";
tex = tex.split("//www");
for (var i = 0; i<tex.length; i++) {
if (tex[i].substring(0, 1) == ".") {
if (tex[i].indexOf(" ")) {
var index = tex[i].indexOf(" ");
tex[i] = " <u><font color='"+linkColor+"'><a href='
http://www"+tex[i].substring(0, tex[i].indexOf(" "))+"'>"+"
http://www"+tex[i].substring(0, tex[i].indexOf(" "))+"</a></font></u>"+tex[i].substring(index);
}
}
}
tex = tex.join("");
tex += " ";
tex = tex.split(" www.");
tex = tex.join(" www.|");
tex = tex.split(" www.");
for (var j = 0; j<tex.length; j++) {
if (tex[j].substring(0, 1) == "|") {
if (tex[j].indexOf(" ")) {
var index = tex[j].indexOf(" ");
tex[j] = "<font color='"+linkColor+"'><a href='
http://www."+tex[j].substring(1, tex[j].indexOf(" "))+"'>"+" <u>www."+tex[j].substring(1, tex[j].indexOf(" "))+"</u>"+"</a></font>"+tex[j].substring(index);
}
}
}
tex = tex.join("");
tex = tex.htmlSpaceFix();
tex = tex.substring(7);
return tex;
};
input = "http
http://www.pixelplay.org this is a link:
http://www.pixelplay.org and these are consecutive links:
http://www.yahoo.com,
www.were-here.com maybetry and fool it with broken one: http:/www.pixelplay.com and maybe another one:
http://9.22.30.101 and throw in a random http and a www and a . and a another : and a ://";
tekst_txt.htmlText = input.hotLink("#990000");