This is a bookmarklet that lets you expand tweets shortened with Lea Verou's tweeplus.com.
Read the usage details.
This is a bookmarklet that lets you expand tweets shortened with Lea Verou's tweeplus.com.
Read the usage details.
/*global unescape, encodeURIComponent */ | |
/*jslint browser: true, sloppy: true, maxerr: 50, indent: 4 */ | |
/* | |
* A bookmarklet for replacing tweeplus.com shortened tweets with their full content. | |
* | |
* USAGE: | |
* Click the tweet, so that it displays in the column on the right, then | |
* activate this bookmarklet. | |
* | |
* Yet another quick hack by @marcoos. | |
* The decode() function and the regexp blatantly stolen from @LeaVerou | |
* | |
*/ | |
(function () { | |
function decode(text) { | |
try { | |
return decodeURIComponent(text.replace(/\+/g, '%20')); | |
} catch (e) { | |
return "Does not compute :("; | |
} | |
} | |
function replacer(str) { | |
var href; | |
if (str.indexOf("@") === 0) { | |
href = "//twitter.com/" + str.substr(1); | |
} else if (str.indexOf("#") === 0) { | |
href = "//twitter.com/#!/search?q=%23" + encodeURIComponent(str.substr(1)); | |
} else { | |
href = str; | |
} | |
return "<a href=" + href + ">" + str + "</a>"; | |
} | |
var links = Array.prototype.slice.call(document.querySelectorAll("a[data-expanded-url^=\"http://tweeplus.com/\"]")); | |
links.forEach(function (link) { | |
var title = link.title, | |
tweetDiv = link.parentNode, | |
tweetText; | |
if (title.indexOf("#") >= 0) { | |
tweetText = decode(link.title.substr(21)); | |
tweetDiv.innerHTML = ""; | |
tweetDiv.appendChild(document.createTextNode(tweetText)); | |
tweetDiv.innerHTML = tweetDiv.innerHTML.replace(/(@\w{1,20}|#\w+|http:\/\/[\w._\+%\/-]+)/g, replacer); | |
} | |
}); | |
}()); |
(function(){function c(f){try{return decodeURIComponent(f.replace(/\+/g,"%20"))}catch(d){return"Does not compute :("}}function b(e){var d;if(e.indexOf("@")===0){d="//twitter.com/"+e.substr(1)}else{if(e.indexOf("#")===0){d="//twitter.com/#!/search?q=%23"+encodeURIComponent(e.substr(1))}else{d=e}}return"<a href="+d+">"+e+"</a>"}var a=Array.prototype.slice.call(document.querySelectorAll('a[data-expanded-url^="http://tweeplus.com/"]'));a.forEach(function(f){var g=f.title,e=f.parentNode,d;if(g.indexOf("#")>=0){d=c(f.title.substr(21));e.innerHTML="";e.appendChild(document.createTextNode(d));e.innerHTML=e.innerHTML.replace(/(@\w{1,20}|#\w+|http:\/\/[\w._\+%\/-]+)/g,b)}})}()); |