Created
October 4, 2010 10:05
-
-
Save timwhitlock/609475 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
retweet.html | |
rt-loader.js |
This file contains hidden or 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 | |
* @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>"RT"</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