Skip to content

Instantly share code, notes, and snippets.

@jaap3 jaap3/retweet.js forked from timwhitlock/.gitignore
Created Oct 4, 2010

Embed
What would you like to do?
/**
* Old School "RT" button hack for #NewTwitter
* @author http://twitter.com/timwhitlock
* @version 1
* @todo deeper integration into twttr.dialogs
*/
(function ( w, d ){
try {
var pc = document.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 {
// ensure we have text area for tweeting
var ta = pc.find('div.tweet-box textarea');
if( ! ta || ! ta.length ){
// fake a click on the home button and come back later
$('#global-nav-home').find('a').click();
return setTimeout( function(){ rt(e); }, 100 );
}
// 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();
ta.attr('value', 'RT @'+name+' '+html ).focus().change();
$(d).scrollTop(0);
}
catch( e ){
alert('Error:\n'+e.message);
}
}
// find outer tweet objects in page and bind an
// event handler that places the old-rt button on
// mouseover.
pc.find('div.tweet:not(:has(.old-rt))').live('mouseover', function(e){
var self = this;
// 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( $(this).find('a.reply-action') )
.click( function(ev){
rt( self );
return false;
} );
});
}
catch( er ){
alert('Error:\n'+er.message);
}
})( window, document );
@jaap3

This comment has been minimized.

Copy link
Owner Author

commented Oct 4, 2010

Instead of an interval to add the RT button to new tweets I use jQuery's live event handler.

I add the 'old-rt' button on mouseover using a selector that only selects tweets that haven't got the 'old-rt' button yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.