rewritten replaceURLWithHTMLLinks to use entities

This commit is contained in:
Jeena Paradies 2011-09-18 23:24:59 +02:00
parent 0190f9a28a
commit 4d49024d62

View file

@ -382,20 +382,16 @@ Twittia.prototype.authorizationHeader = function(method, url, params) {
function replaceURLWithHTMLLinks(text, entities, message_node) {
var urls = entities.urls;
var words = text.split(" ");
for(var i = 0; i<urls.length; i++) {
for(var word in words) {
var original = words[word] + "";
var original = urls[i].url;
var replace = urls[i].expanded_url == null ? original : urls[i].expanded_url;
if(words[word].startsWith("http://t.co/")) {
var replace = findTCOLongURL(words[word], urls);
if(replace != null) {
if(replace.startsWith("http://bit.ly/") || replace.startsWith("http://j.mp/")) {
replaceShortened(replace, message_node);
}
words[word] = "<a href='" + words[word] + "'>" + replace + "</a>";
text = text.replace(original, "<a href='" + original + "'>" + replace + "</a>");
var media = null;
@ -429,30 +425,9 @@ function replaceURLWithHTMLLinks(text, entities, message_node) {
}
}
} else {
words[word] = "<a href='" + words[word] + "'>" + words[word] + "</a>";
}
} else if(words[word].startsWith("http://") || words[word].startsWith("https://") || words[word].startsWith("file://") || words[word].startsWith("ftp://")) {
if(words[word].startsWith("http://bit.ly/") || words[word].startsWith("http://j.mp/")) {
replaceShortened(words[word], message_node);
}
words[word] = "<a href='" + words[word] + "'>" + words[word] + "</a>";
}
}
text = words.join(" ");
return text; // text.replace(exp,"<a href='$1'>$1</a>");
}
function findTCOLongURL(url, urls) {
for(var u in urls) {
if(urls[u].url == url) {
return urls[u].expanded_url;
}
}
return null;
return text;
}
function replaceTwitterLinks(text) {
@ -484,6 +459,7 @@ String.prototype.endsWith = function(suffix) {
function getUrlVars(url)
{
var vars = [], hash;
if(url.indexOf("#") > -1) url = url.slice(0, url.indexOf("#"));
var hashes = url.slice(url.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{