Skip to content

Instantly share code, notes, and snippets.

@maraigue
Created May 24, 2009 02:27
Show Gist options
  • Select an option

  • Save maraigue/116915 to your computer and use it in GitHub Desktop.

Select an option

Save maraigue/116915 to your computer and use it in GitHub Desktop.
Source code for Twitter "ReTweet" bookmarklet (use in Twitter status page)
(function(){
var h,x,b;
if(location.href.match(/^https?:\/\/(m\.|explore\.)?twitter\.com\/([0-9A-Z_a-z]+)\/status/)){
h="RT+@"+RegExp.$2+":+";
}else{
alert("Not in a tweet page!");
return;
}
x=(document.getElementsByTagName("body"))[0].innerHTML.match(/<span class="?entry-content"?>(.+?)<\/span>/ig);
if(x && x.length==1){
b=RegExp.$1;
b=b.replace(/@<a href="?\/([0-9A-Z_a-z]+)"?>\1<\/a>/ig,function(s,p){return "@"+p;});
b=b.replace(/<a [^>]*?class="?hashtag"?[^>]*?>#(.+?)<\/a>/ig,function(s,p){return "#"+p;});
b=b.replace(/<a href="?(https?:\/\/.+?)"? rel="?nofollow"? target="?_blank"?>.+?<\/a>/ig,function(s,p){return p;});
location.href="http://twitter.com/?status="+h+encodeURIComponent(b);
}else{
alert("Can not extract the tweet!");
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment