HTML5 tweet time range

HTML5 tweet time range.





HTML5 tweet time range

  body { font-family: helvetica, arial;}



  
    
    Select a time range of recent HTML5 tweets
    5 minutes
    30 minutes
    2 hours
    all time
    
  
  
    var tweetEl = document.getElementById('tweets'); var db; var callback = saveTweets; function getTweets() { var script = document.createElement('script'); script.src = 'http://search.twitter.com/search.json?q=html5 -RT&rpp=100&callback=saveTweets'; document.body.appendChild(script); } // our Twitter API callback function function saveTweets(tweets) { for (var i = 0; i strftime("%s", "now", "-' + amount + ' minutes")' : ''), [], function (tx, results) { var html = []; tweetEl.innerHTML = ''; document.querySelector('#found').innerHTML = ' (found: ' + results.rows.length + ')'; if (results.rows && results.rows.length) { for (var i = 0; i < results.rows.length; i++) { html.push('
  1. ' + ify.clean(results.rows.item(i).text) + ' [posted ' + relative_time(results.rows.item(i).date*1000) + ']
  2. '); } tweetEl.innerHTML = html.join(''); } }); }); } function relative_time(d) { var date = new Date(d), relative_to = new Date(), delta = ~~((relative_to.getTime() - date.getTime()) / 1000), r = ''; delta = delta + (relative_to.getTimezoneOffset() * 60); if (delta < 5) { r = 'less than 5 seconds ago'; } else if (delta < 30) { r = 'half a minute ago'; } else if (delta < 60) { r = 'less than a minute ago'; } else if (delta < 120) { r = '1 minute ago'; } else if (delta < (45*60)) { r = (~~(delta / 60)).toString() + ' minutes ago'; } else if (delta < (2*90*60)) { // 2* because sometimes read 1 hours ago r = 'about 1 hour ago'; } else if (delta < (24*60*60)) { r = 'about ' + (~~(delta / 3600)).toString() + ' hours ago'; } else { r = date.toString(); } return r; } [].forEach.call(document.querySelectorAll('input[type=radio]'), function (el) { el.onclick = function () { show(this.value); } }); function setupDatabase() { if (!window.openDatabase) { tweetEl.innerHTML = '
  3. Web SQL Database API is not available in this browser, please try nightly Opera, Webkit or Chrome.
  4. '; return; } db = openDatabase('tweets', '1.0', 'db of tweets', 2 * 1024 * 1024); db.transaction(function (tx) { tx.executeSql('DROP TABLE IF EXISTS tweets'); tx.executeSql('CREATE TABLE IF NOT EXISTS tweets (id unique, screen_name, date integer, text)'); }); getTweets(); } setupDatabase();
    This entry was posted in Uncategorized. Bookmark the permalink.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s