//var glb_search = '#ows'; var glb_search = ''; var glb_lang = 'all'; var timer = 0; var iphone; function dotrends() { $('#trends').html(''); $.getJSON("http://search.twitter.com/trends.json?callback=?", trends_h); } function trends_h(data) { var topic, topic_fix; $('#trends').html('Trending Topics:

'); for(var i in data.trends) { topic = data.trends[i].name; topic_fix = fix_topic(topic); $('#trends').append('· ' + topic + '
'); //$('#trends').append('· ' + topic + '
'); } $('#trends').append('

Refresh Trends'); } function fix_topic(s) { var match = / /.test(s); if (match) { s = '"' + s + '"'; } return jtw_urlencode(s); } function fix_topic2(s) { s = s.replace("'", "\\\'"); s = s.replace("%27", "\\%27"); //window.alert(s); return s; } function jtw_urlencode(str) { str = escape(str); str = str.replace(/\+/g, '%2B'); str = str.replace(/%20/g, '+'); str = str.replace(/\*/g, '%2A'); str = str.replace(/\//g, '%2F'); str = str.replace(/@/g, '%40'); str = str.replace(/#/g, '%23'); return str; } function jsonp_proxy(url, callback) { $.getJSON(url, function(data){ //window.alert(arr.length); callback(data); }); } function do_search(lastid, callback) { twitter_search_proxy(jtw_urlencode(glb_search), lastid, callback); } function twitter_search_proxy(search, lastid, callback) { //search should already be url encoded var url; var since_str = ""; var rpp = 100; if (iphone == 1) { rpp = 20; } if (lastid > 0) { since_str = "&since_id=" + lastid + ""; } url = "http://search.twitter.com/search.json?q=" + search + since_str + "&rpp=" + rpp + "&lang=" + glb_lang + "&callback=?" jsonp_proxy(url, callback); } function formattweet(user,tweet,tstamp,img,tid,lastid) { var ret = ''; var re = new RegExp("(([a-zA-Z]+:\/\/)([a-zA-Z][a-zA-Z0-9_\.-]*[a-zA-Z]{2,6})([a-zA-Z0-9$~\#\/\._\?\&%-=]*[a-zA-Z0-9$~\#\/_\?\&%-=]))", "g"); tweet = tweet.replace(re, '$1'); re = new RegExp("@([a-zA-Z0-9_]+)", "g"); tweet = tweet.replace(re, '@$1'); tweet = tweet.replace(/&/g, '&'); ret = ret + '

'; return ret; } function dosearch_bottom(arr) { var ret = ""; var lastid; if (arr.results.length > 0) { lastid = arr.results[0].id; for (var i = 0; i < arr.results.length; i++) { var user = arr.results[i].from_user; var tweet = arr.results[i].text; var tstamp = arr.results[i].created_at; tstamp = new Date(tstamp); //tstamp = tstamp.format('D M d - g:i:s a'); tstamp = tstamp.toLocaleString(); var img = arr.results[i].profile_image_url; var tid = arr.results[i].id; ret = ret + formattweet(user,tweet,tstamp,img,tid,lastid); } // end for $('#results').prepend(ret); $('#results .newtweet-' + lastid).fadeIn("slow"); //$('#results .newtweetsdiv:first').fadeIn("slow"); $('#results').attr('lastid', lastid); refresh_interval = 8000; } else { refresh_interval = Math.floor(refresh_interval * 1.15); if (refresh_interval > 60000) { refresh_interval = 60000; } } $('.tweetdisplay:gt(350)').remove(); lastid = $('#results').attr('lastid'); //timer = setTimeout('twitter_search_proxy(jtw_urlencode(\'#ows\'), ' + lastid.toString() + ', dosearch_bottom);', refresh_interval); //timer = setTimeout('twitter_search_proxy(jtw_urlencode(\'' + glb_search + '\'), ' + lastid.toString() + ', dosearch_bottom);', refresh_interval); timer = setTimeout('do_search(' + lastid.toString() + ', dosearch_bottom);', refresh_interval); } function pause() { clearTimeout(timer); $('#pause').text('Unpause'); } function unpause() { refresh_interval = 8000; lastid = $('#results').attr('lastid'); //timer = setTimeout('twitter_search_proxy(jtw_urlencode(\'#ows\'), ' + lastid.toString() + ', dosearch_bottom);', 500); //timer = setTimeout('twitter_search_proxy(jtw_urlencode(\'' + glb_search + '\'), ' + lastid.toString() + ', dosearch_bottom);', 500); timer = setTimeout('do_search(' + lastid.toString() + ', dosearch_bottom);', 500); $('#pause').text('Pause'); } function doretweet_new(user, tid) { $('#tdiv_tweet').val('RT @' + user + ': ' + $('#tweet-'+tid).text()).focus(); updatecharsnew($('#tdiv_tweet').val()); } function changelanguage_search() { glb_lang = $('#lang').val(); pause(); $('#results').attr('lastid', 0); $('#results').empty(); unpause(); } function searchclick(ev) { newsearch = $('#si').val(); changesearch(newsearch); } function trendclick(newsearch) { newsearch = newsearch.replace("+", " "); $('#si').val(newsearch); changesearch(newsearch); } function changesearch(newsearch) { newsearch = newsearch.replace("'", "\\\\\\'"); glb_search = newsearch; update_autotweet(newsearch); pause(); $('#results').attr('lastid', 0); $('#results').empty(); unpause(); } function update_autotweet(search) { var patt=new RegExp("#"); auto_tweet = 'I\'m searching for ' + search + ' live on TweetGrid Search - http://tweetgrid.com/search?q=' + jtw_urlencode(search); $('#tdiv_tweet').val(auto_tweet); if (patt.test(search)) { $('#tdiv_hashtag').val(search); } else { $('#tdiv_hashtag').val('#'); } updatecharsnew($('#tdiv_tweet').val()); } function langsel() { $('#langdiv').html('
Language

'); }