-
-
Save jaap3/610115 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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>"RT"</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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.