rewritten replaceURLWithHTMLLinks to use entities
This commit is contained in:
parent
0190f9a28a
commit
4d49024d62
1 changed files with 41 additions and 65 deletions
|
@ -382,20 +382,16 @@ Twittia.prototype.authorizationHeader = function(method, url, params) {
|
||||||
function replaceURLWithHTMLLinks(text, entities, message_node) {
|
function replaceURLWithHTMLLinks(text, entities, message_node) {
|
||||||
var urls = entities.urls;
|
var urls = entities.urls;
|
||||||
|
|
||||||
var words = text.split(" ");
|
for(var i = 0; i<urls.length; i++) {
|
||||||
|
|
||||||
for(var word in words) {
|
var original = urls[i].url;
|
||||||
var original = words[word] + "";
|
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/")) {
|
if(replace.startsWith("http://bit.ly/") || replace.startsWith("http://j.mp/")) {
|
||||||
replaceShortened(replace, message_node);
|
replaceShortened(replace, message_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
words[word] = "<a href='" + words[word] + "'>" + replace + "</a>";
|
text = text.replace(original, "<a href='" + original + "'>" + replace + "</a>");
|
||||||
|
|
||||||
var media = null;
|
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>";
|
return text;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceTwitterLinks(text) {
|
function replaceTwitterLinks(text) {
|
||||||
|
@ -484,6 +459,7 @@ String.prototype.endsWith = function(suffix) {
|
||||||
function getUrlVars(url)
|
function getUrlVars(url)
|
||||||
{
|
{
|
||||||
var vars = [], hash;
|
var vars = [], hash;
|
||||||
|
if(url.indexOf("#") > -1) url = url.slice(0, url.indexOf("#"));
|
||||||
var hashes = url.slice(url.indexOf('?') + 1).split('&');
|
var hashes = url.slice(url.indexOf('?') + 1).split('&');
|
||||||
for(var i = 0; i < hashes.length; i++)
|
for(var i = 0; i < hashes.length; i++)
|
||||||
{
|
{
|
||||||
|
|
Reference in a new issue