Twitter API (javascript)

Web Programing/JavaScript 2011. 8. 23. 11:34

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

<form id="frm" name="frm" action="/" method="get" onsubmit="javascript:getTweets(); return false;" >
		<h3>Twitter API (javascript)</h3>
		<div style="width:640px; min-height:40px;border:1px solid skyblue; padding:15px;">
			<div>
				screenName : <input type="text" id="screenName" value="wowhyun" />, 
				count : <input type="text" id="count" value="5" />
				<input type="submit" value="트윗 가져오기" />
			</div>
			<div>
				<input type="button" value="Limit 확인" id="getLimitBtn" /> 
				<span id="remaining-hits"></span>
			</div>
		</div>
		<div style="width:640px; min-height:40px; border:1px solid green; margin-top:10px; padding:15px;">
				<ol id="twitterList"></ol>
		</div>
</form>

<script type="text/javascript">
function chkTweetLinks(s){
	var regLink = new RegExp('(http|https|ftp|telnet|news|irc)://([-/.a-zA-Z0-9_~#%$?&=:200-377()]+)','gi');
	var r = s.replace(regLink,'<a href="$1://$2" target="_blank">$1://$2</a>')
		.replace(/(^|\s)@(\w+)/g, '$1@<a href="http://www.twitter.com/$2" target="_blank">$2</a>')
		.replace(/(^|\s)#(\w+)/g, '$1#<a href="http://search.twitter.com/search?q=%23$2" target="_blank">$2</a>');
	return r;
}
function getTweets(){
	jQuery.getJSON(
		'http://api.twitter.com/1/statuses/user_timeline.json?trim_user=t&include_rts=true&callback=?',
		{ screen_name: $('#screenName').val(), count: $('#count').val() },
		function(data){
			$('#twitterList').hide();
			$('#twitterList').empty();
			jQuery.each(data, function(i,item){
				$('#twitterList').append('<li>'+chkTweetLinks(item.text)+'<br /> -'+item.created_at+'</li>');
			});
			$('#twitterList').fadeIn('slow');
			getRemainLimits();
    }
	);
}

function getRemainLimits(){
	$('#remaining-hits').hide();
	jQuery.getJSON(
		'http://api.twitter.com/1/account/rate_limit_status.json?callback=?',
		function(data){
			$('#remaining-hits').html(data['remaining_hits']+' (reset_time : '+data['reset_time']+') ');
			$('#remaining-hits').fadeIn('slow');
    }
	);
}

$(function () {
    $('#getLimitBtn').click(getRemainLimits);
    getTweets();
});
</script>

설정

트랙백

댓글

[JavaScript] 오늘 하루 창 닫기

Web Programing/JavaScript 2007. 12. 26. 16:52

<script type="text/javascript">
function setCookie(name, value, expiredays){
    var todayDate = new Date();
    todayDate.setDate(todayDate.getDate() + expiredays);
    document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function closeWin(){
    if(document.checkClose.Notice.checked){
        setCookie( "popup_1211", "1" , 1);
    }
    self.close();
}
</script>


<form name="checkClose">
<input type="checkbox" name="Notice" onclick="javscript:closeWin();" />
</form>


<script type="text/javascript">
function init(){
    if(getCookie("popup_1211") != "1"){
        window.open("popup_1211.html", "ad_pop", "width=350,height=350,left=0,top=0,alwaysRaised=yes,toolbar=no,scrollbars=no");
    }
}
function getCookie( name ){
    var nameOfCookie = name + "=";
    var x = 0;
    while ( x <= document.cookie.length ) {
        var y = (x+nameOfCookie.length);
        if ( document.cookie.substring( x, y ) == nameOfCookie ) {
            if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
            endOfCookie = document.cookie.length;
            return unescape( document.cookie.substring( y, endOfCookie ) );
        }
        x = document.cookie.indexOf( " ", x ) + 1;
        if ( x == 0 )
        break;
    }
    return "";
}
</script>

설정

트랙백

댓글

  • longchamp 2013.07.26 20:36 ADDR 수정/삭제 답글

    눈을 감아봐 입가에 미소가 떠오르면 네가 사랑하는 그 사람이 널 사랑하고 있는거야.

  • coach outlet 2013.07.28 14:20 ADDR 수정/삭제 답글

    당신 매력있어, 자기가 얼마나 매력있는지 모르는게 당신매력이야