Created
November 3, 2009 22:29
-
-
Save tekkub/225512 to your computer and use it in GitHub Desktop.
Add @github's tweets to your dashboard
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
// ==UserScript== | |
// @name GitHub Dashboard Twitter | |
// @namespace http://tekkub.net/ | |
// @include https://github.com/ | |
// ==/UserScript== | |
$("div.news h1").before( | |
$("<div>").attr("id", "twitter_div2").append( | |
$("<h1>").text("GitHub status ").css({ | |
'border-bottom' : '1px solid rgb(170, 170, 170)', | |
}).append( | |
$("<a>").css("float", "right").attr("href", "http://twitter.com/github").attr("target", "_blank").text("follow us on twitter") | |
) | |
).append( | |
$("<div>").addClass("alert").append( | |
$("<div>").addClass("title").text("Loading... ").append( | |
$("<img>").attr("src", "/images/modules/ajax/indicator.gif") | |
) | |
) | |
) | |
) | |
$.getJSON("http://twitter.com/statuses/user_timeline/github.json?callback=?", function(data) { | |
$("#twitter_div2 div").remove(); | |
var has_updates = false | |
var shown = 0 | |
$.each(data, function(i,item) { | |
if (item.text[0] != '@' && item.text[0] != 'R' && item.text[1] != 'T' && was_recent(item.created_at) && shown < 2) { | |
shown++ | |
has_updates = true | |
var linked_content = item.text.replace(/(https?:\/\/[^ ;|\\*'"!,()<>]+\/?)/g,'<a href="$1">$1</a>'); | |
$("#twitter_div2").append( | |
$("<div>").addClass("alert").css("background", "url(http://assets1.twitter.com/images/favicon.ico) no-repeat").append( | |
$("<div>").addClass("body").append( | |
$("<div>").addClass("details").html(linked_content).append( | |
$("<p>").append( | |
$("<a>").attr("target", "_blank").attr("href", "http://twitter.com/github/statuses/" + item.id).text(relative_time(item.created_at)) //.relatizeDate() | |
) | |
) | |
) | |
) | |
) | |
} | |
}) | |
if (!has_updates) { | |
$("#twitter_div2").append( | |
$("<div>").addClass("alert").append( | |
$("<div>").addClass("body").append( | |
$("<div>").addClass("details").text("No updates!") | |
) | |
) | |
) | |
} | |
}) | |
var num_days = 2 | |
function was_recent(timestamp) { | |
var B = timestamp.split(" ") | |
timestamp = B[1]+" "+B[2]+", "+B[5]+" "+B[3] | |
var parsed_timestamp = Date.parse(timestamp) | |
var D = new Date() | |
var seconds_different = parseInt((D.getTime() - parsed_timestamp) / 1000) | |
return (seconds_different + (D.getTimezoneOffset() * 60)) < (60 * 60 * 24 * num_days) | |
} | |
function relative_time(C) { | |
var B=C.split(" "); | |
C=B[1]+" "+B[2]+", "+B[5]+" "+B[3]; | |
var A=Date.parse(C); | |
var D=(arguments.length>1)?arguments[1]:new Date(); | |
var E=parseInt((D.getTime()-A)/1000);E=E+(D.getTimezoneOffset()*60); | |
if(E<60){ | |
return"less than a minute ago" | |
} else { | |
if(E<120){ | |
return"about a minute ago" | |
} else { | |
if(E<(60*60)){ | |
return(parseInt(E/60)).toString()+" minutes ago" | |
} else { | |
if(E<(120*60)){ | |
return"about an hour ago" | |
} else { | |
if(E<(24*60*60)){ | |
return"about "+(parseInt(E/3600)).toString()+" hours ago" | |
} else { | |
if(E<(48*60*60)){ | |
return"1 day ago" | |
} else { | |
return(parseInt(E/86400)).toString()+" days ago" | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment