Skip to content

Instantly share code, notes, and snippets.

@timwhitlock
Created October 4, 2010 10:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timwhitlock/609475 to your computer and use it in GitHub Desktop.
Save timwhitlock/609475 to your computer and use it in GitHub Desktop.
retweet.html
rt-loader.js
/**
* Old School "RT" button hack for #NewTwitter
* @author http://twitter.com/timwhitlock
* @history 1.0 first release
* @version 1.1 intergated integrated into twttr dialog
*/
(function ( w, d ){
try {
var pc = d.getElementById('page-container');
if( ! pc || ! w.jQuery || ! /twitter\.com$/.test(w.location.host) ){
throw new Error("Please make sure you're on the new twitter.com and try again");
}
pc = $(pc);
// retweet function; accepts native .tweet element
function rt( e ){
try {
// get original tweet from meta attributes
var name = $(e).attr('data-screen-name');
// rip tweet text from .tweet element's innerHTML
var html = $(e).find('div.tweet-text').text();
new twttr.widget.TweetDialog({
modal: false,
draggable: true,
template: {
title: _("Retweet @"+name)
},
defaultContent: 'RT @'+name+' '+html,
origin: "old-school-RT-hack-sorry-twitter"
}).open().focus();
}
catch( e ){
alert('Error:\n'+e.message);
}
}
// converting function, runs on enable and then on interval
function exec(){
try {
// find outer tweet objects in page
pc.find('div.tweet').each(function(i,e){
// ignore existing retweet buttons
if( ! $(e).find('a.old-rt').length ){
// add our own button after the reply button
$('<a href="#" class="retweet-action old-rt"><span><i></i><b>&quot;RT&quot;</b></span></a>')
.insertAfter( $(e).find('a.reply-action') )
.click( function(ev){
rt( e );
return false;
} );
}
});
}
catch( Er ){
/*alert('Error:\n'+er.message);*/
}
}
exec();
setInterval( exec, 500 );
}
catch( er ){
alert('Error:\n'+er.message);
}
})( window, document );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment