diff --git a/TwittiaCore.js b/TwittiaCore.js index e4449f8..c0a79ca 100644 --- a/TwittiaCore.js +++ b/TwittiaCore.js @@ -93,7 +93,7 @@ Twittia.prototype.getItem = function(status) { else template.in_reply.parentNode.className = "hidden"; template.in_reply.href = WEBSITE_PATH + status.in_reply_to_screen_name + "/status/" + status.in_reply_to_status_id_str; - template.message.innerHTML = replaceTwitterLinks(replaceURLWithHTMLLinks(status.text)); + template.message.innerHTML = replaceTwitterLinks(replaceURLWithHTMLLinks(status.text, status.entities)); var time = document.createElement("abbr"); time.innerText = status.created_at; @@ -110,6 +110,38 @@ Twittia.prototype.getItem = function(status) { } template.source.innerHTML = status.source; + + if(status.entities.media) { + + for(var i=0; i$1"); +function replaceURLWithHTMLLinks(text, entities) { + //var exp = /(\b(https?|ftp|file):\/\/\S+)/ig; + var urls = entities.urls; + + var words = text.split(" "); + + for(var word in words) { + if(words[word].startsWith("http://t.co/")) { + var replace = findTCOLongURL(words[word], urls); + + if(replace != null) { + words[word] = "" + replace + ""; + + var media = null; + + if(replace.startsWith("http://youtube.com/") || replace.startsWith("http://www.youtube.com/")) { + media = { + type: "twittia_youtube", + url: replace, + media_url: "http://img.youtube.com/vi/" + getUrlVars(replace)["v"] + "/1.jpg" + } + + } else if (replace.startsWith("http://twitpic.com/")) { + media = { + type: "photo", + url: replace, + media_url: "http://twitpic.com/show/mini/" + replace.substring("http://twitpic.com/".length) + } + + } else if (replace.startsWith("http://yfrog")) { + media = { + type: "photo", + url: replace, + media_url: replace + } + } + + if(media) { + if(entities.media) { + entities.media.push(media); + } else { + entities.media = [media]; + } + } + + } else { + words[word] = "" + words[word] + ""; + } + } else if(words[word].startsWith("http://") || words[word].startsWith("https://") || words[word].startsWith("file://") || words[word].startsWith("ftp://")) { + words[word] = "" + words[word] + ""; + } + } + + text = words.join(" "); + + return text; // text.replace(exp,"$1"); +} + +function findTCOLongURL(url, urls) { + for(var u in urls) { + if(urls[u].url == url) { + return urls[u].expanded_url; + } + } + return null; } function replaceTwitterLinks(text) { @@ -366,5 +465,27 @@ function loadPlugin(url) { document.getElementsByTagName("head")[0].appendChild(plugin); } +String.prototype.startsWith = function(prefix) { + return this.indexOf(prefix) === 0; +} + +String.prototype.endsWith = function(suffix) { + return this.match(suffix+"$") == suffix; +}; + +function getUrlVars(url) +{ + var vars = [], hash; + var hashes = url.slice(url.indexOf('?') + 1).split('&'); + for(var i = 0; i < hashes.length; i++) + { + hash = hashes[i].split('='); + vars.push(hash[0]); + vars[hash[0]] = hash[1]; + } + return vars; +} + + var twittia_instance; diff --git a/default.css b/default.css index 10cf89e..4cf877a 100644 --- a/default.css +++ b/default.css @@ -112,6 +112,19 @@ p { height: 75px; } +.images:empty { + display: none; +} + +.images { + padding-top: 5px; +} + +.images img { + border-radius: 5px; + max-height: 75px; +} + .delete { font-weight: normal; color: #555;