# # Repurposed from example by Manas Tungare, manas@tungare.name # URL: http://manas.tungare.name/software/twitter-php-script/ # button_html = () -> ' Follow pikuseru on Twitter ' tweet_time_html = (data) -> "#{to_nicetime data.created_at} #{button_html()}" tweet_text_html = (data) -> " #{hyperlink data.text}" hyperlink = (text) -> text.replace(/(http:\/\/(.*?)\/[^ ]*)/gi, '$1') to_nicetime = (timestamp) -> seconds = (new Date().getTime() - new Date(timestamp).getTime()) / 1000 minutes = Math.floor(seconds / 60) hours = Math.floor(seconds / 3600) days = Math.floor(seconds / 86400) return 'less than a minute ago' if seconds < 60 return 'about a minute ago' if seconds < 120 return "#{minutes} minutes ago" if seconds < 45 * 60 return 'about an hour ago' if seconds < 90 * 60 or hours == 1 return "about #{hours} hours ago" if seconds < 24 * 60 * 60 return '1 day ago' if seconds < 48 * 60 * 60 return "#{days} days ago" update_page = (data) -> $('#tweet_text').html tweet_text_html data $('#tweet_time').html tweet_time_html data $('#tweet_user').attr 'src', data.profile_image_url $('#tweet').fadeIn 500 load_tweets = () -> $.getJSON('tweet.json', (data, response) -> update_page(data) if response == "success" setTimeout load_tweets, 1000 * 60 ) $(document).ready -> load_tweets()