Skip to content

Instantly share code, notes, and snippets.

@tswicegood
Created November 29, 2009 23:33
Show Gist options
  • Save tswicegood/245129 to your computer and use it in GitHub Desktop.
Save tswicegood/245129 to your computer and use it in GitHub Desktop.
Twitterpack
jetpack.future.import("pageMods");
var twitter_jetpack_callback = function(doc) {
// var doc = document; // uncomment to run directly in Firebug
$('body', doc).append($('<h1>jetpack!</h1>', doc));
var selector_text = 'a:contains("in reply to")';
var selector_for_more = '#pagination a';
var in_reply_handler = function() {
// This is to handle craziness in the way that Jetpack wraps the DOM / Document
// (not sure which wording is correct) which kills parents('li') return.
// Instead, we have to rely on the more brittle version of manually pulling
// it out of the expected return values.
//
// This breaks as soon as Twitter changes their HTML structure.
var li = $($(this, doc).parents()[2]);
var display_reply = function(data) {
// Process data via doc so it's parseable. Otherwise, we end up getting
// those nasty (and very unhelpful) context errors from jQuery.
var response = $(data, doc);
var entry = $('.hentry.status', response);
entry.css('padding-left', '50px');
var thumb = $('.thumb', response);
thumb.css('padding-left', '50px');
var new_li = $('<li class="hentry status"></li>', doc);
new_li.css({
'background-repeat': 'no-repeat',
'background-position': '15px 10px',
'background-image': 'url(http://domain51.com/in-reply-arrow.png)'
});
li.after(new_li);
new_li.append(thumb);
new_li.append(entry);
var author = $('<strong></strong>', doc).append($('.tweet-url.screen-name', response));
$('.status-body', entry).prepend(author);
$(selector_text, new_li).each(add_in_reply_handler);
};
$.get(this.href, display_reply);
return false;
};
var add_in_reply_handler = function(idx, el) {
$(el, doc).click(in_reply_handler);
};
$(selector_text, doc).each(add_in_reply_handler);
$(doc).ajaxComplete(function() {
$(selector_text, doc).each(add_in_reply_handler);
});
};
var options = {};
options.matches = ["http://twitter.com/*",
"https://twitter.com/*"]
jetpack.pageMods.add(twitter_jetpack_callback, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment