Created
July 20, 2012 12:27
-
-
Save LanF3usT/3150471 to your computer and use it in GitHub Desktop.
Affichage des derniers tweets
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
$.fn.twitterCallback = (twitters) -> | |
return @ if @length == 0 | |
statusHTML = [] | |
i = 0 | |
while i < twitters.length | |
username = twitters[i].user.screen_name | |
status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, (url) -> | |
"<a href=\"" + url + "\">" + url + "</a>" | |
).replace(/\B@([_a-z0-9]+)/g, (reply) -> | |
reply.charAt(0) + "<a href=\"http://twitter.com/" + reply.substring(1) + "\">" + reply.substring(1) + "</a>" | |
) | |
statusHTML.push "<li><span>" + status + "</span> <a style=\"font-size:85%\" href=\"http://twitter.com/" + username + "/statuses/" + twitters[i].id_str + "\">" + relative_time(twitters[i].created_at) + "</a></li>" | |
i++ | |
$(@).append(statusHTML.join("")) | |
relative_time = (time_value) -> | |
values = time_value.split(" ") | |
time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3] | |
parsed_date = Date.parse(time_value) | |
relative_to = (if (arguments.length > 1) then arguments[1] else new Date()) | |
delta = parseInt((relative_to.getTime() - parsed_date) / 1000) | |
delta = delta + (relative_to.getTimezoneOffset() * 60) | |
if delta < 60 | |
"less than a minute ago" | |
else if delta < 120 | |
"about a minute ago" | |
else if delta < (60 * 60) | |
(parseInt(delta / 60)).toString() + " minutes ago" | |
else if delta < (120 * 60) | |
"about an hour ago" | |
else if delta < (24 * 60 * 60) | |
"about " + (parseInt(delta / 3600)).toString() + " hours ago" | |
else if delta < (48 * 60 * 60) | |
"1 day ago" | |
else | |
(parseInt(delta / 86400)).toString() + " days ago" | |
$(document).ready -> | |
$.getJSON("https://api.twitter.com/1/statuses/user_timeline.json", | |
"include_entities=true&include_rts=true&screen_name=MVCDLM&count=5&callback=?", | |
(data) -> | |
$('body').twitterCallback(data) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment