Created
          September 12, 2011 21:04 
        
      - 
      
- 
        Save fael/1212422 to your computer and use it in GitHub Desktop. 
    Get and format tweets
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | getTweets = function(alvo, usuario, qtdMensagens){ | |
| var o = {} | |
| o.qtdMensagens = qtdMensagens; | |
| o.caixaTwitter = $("#" + alvo); | |
| o.caixaTwitter.append("<li><a href='#'>carregando tweets...</a></li>"); | |
| $.jTwitter(usuario, o.qtdMensagens, function(data){ | |
| o.caixaTwitter.empty(); | |
| o.list = ''; | |
| $.each(data, function(i, post){ | |
| o.hora = H(post.created_at); | |
| o.texto = formatTwitString(post.text); | |
| o.list += '<li>' + o.texto + "<span class='hora'>" + o.hora + '</span></li>'; | |
| }); | |
| o.caixaTwitter.append(o.list); | |
| }); | |
| } | |
| formatTwitString = function(str){ | |
| str=' '+str; | |
| str = str.replace(/((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a href="$1" target="_blank">$1</a>'); | |
| str = str.replace(/([^\w])\@([\w\-]+)/gm,'$1@<a href="http://twitter.com/$2" target="_blank">$2</a>'); | |
| str = str.replace(/([^\w])\#([\w\-]+)/gm,'$1<a href="http://twitter.com/search?q=%23$2" target="_blank">#$2</a>'); | |
| return str; | |
| } | |
| // from http://widgets.twimg.com/j/1/widget.js | |
| var K = function () { | |
| var a = navigator.userAgent; | |
| return { | |
| ie: a.match(/MSIE\s([^;]*)/) | |
| } | |
| }(); | |
| var H = function (a) { | |
| var b = new Date(); | |
| var c = new Date(a); | |
| if (K.ie) { | |
| c = Date.parse(a.replace(/( \+)/, ' UTC$1')) | |
| } | |
| var d = b - c; | |
| var e = 1000, | |
| minute = e * 60, | |
| hour = minute * 60, | |
| day = hour * 24, | |
| week = day * 7; | |
| if (isNaN(d) || d < 0) { | |
| return "" | |
| } | |
| if (d < e * 7) { | |
| return "agora pouco" | |
| } | |
| if (d < minute) { | |
| return Math.floor(d / e) + " segundos atrás" | |
| } | |
| if (d < minute * 2) { | |
| return "há 1 minuto" | |
| } | |
| if (d < hour) { | |
| return "há " + Math.floor(d / minute) + " minutos" | |
| } | |
| if (d < hour * 2) { | |
| return "há 1 hora" | |
| } | |
| if (d < day) { | |
| return "há " + Math.floor(d / hour) + " horas atrás" | |
| } | |
| if (d > day && d < day * 2) { | |
| return "ontem" | |
| } | |
| if (d < day * 365) { | |
| return "há " + Math.floor(d / day) + " dias" | |
| } else { | |
| return "há mais de 1 ano" | |
| } | |
| }; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment