jQuery ile yazılmış, belirttiğimiz kullanıcı adlarının, Twitter üzerinden son girdilerini JSON ile çeken bir script.
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
| var tweetUsers = [ 'yusufdoru' , 'TechCrunch' , 'smashingmag' , 'mashable' ]; // Twitlerini çekmek istediğiniz Twitter kullanıcıların kullanıcı adları var buildString = "" ; $(document).ready( function (){ // After the page is loaded $( '#twitter-ticker' ).slideDown( 'slow' ); // Show the ticker for ( var i=0;i<tweetUsers.length;i++) { // Build the search api parameters if (i!=0) buildString+= '+OR+' ; buildString+= 'from:' +tweetUsers[i]; } var fileref = document.createElement( 'script' ); // Creating a new script element fileref.setAttribute( "type" , "text/javascript" ); fileref.setAttribute( "src" , "http://search.twitter.com/search.json?q=" +buildString+ "&callback=TweetTick&rpp=50" ); // Setting its src to the search API URL; We provide TweetTick as a callback document.getElementsByTagName( "head" )[0].appendChild(fileref); // Appending it to the head of the page and thus executing it }); function TweetTick(ob) { // This is the callback function var container=$( '#tweet-container' ); container.html( '' ); // Removing the loading gif animation $(ob.results).each( function (el){ // ob contains all the tweets var str = ' <div class="tweet">\ <div class="avatar"><a href="http://twitter.com/' + this .from_user+ '" target="_blank"><img src="' + this .profile_image_url+ '" alt="' + this .from_user+ '" /></a></div>\ <div class="user"><a href="http://twitter.com/' + this .from_user+ '" target="_blank">' + this .from_user+ '</a></div>\ <div class="time">' +relativeTime( this .created_at)+ '</div>\ <div class="txt">' +formatTwitString( this .text)+ '</div>\ </div>' ; container.append(str); // Adding the tweet to the container }); container.jScrollPane(); // After all the tweets have been added, create the slidebar } function formatTwitString(str) { // This function formats the tweet body text str= ' ' +str; str = str.replace(/((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm, '<a href="$1" target="_blank">$1</a>' ); // The tweets arrive as plain text, so we replace all the textual URLs with hyperlinks str = str.replace(/([^\w])\@([\w\-]+)/gm, '$1@<a href="http://twitter.com/$2" target="_blank">$2</a>' ); // Replace the mentions str = str.replace(/([^\w])\ #([\w\-]+)/gm,'$1<a href="http://twitter.com/search?q=%23$2" target="_blank">#$2</a>'); // Replace the hashtags return str; } function relativeTime(pastTime) { // Generate a JavaScript relative time for the tweets var origStamp = Date.parse(pastTime); var curDate = new Date(); var currentStamp = curDate.getTime(); var difference = parseInt((currentStamp - origStamp)/1000); if (difference < 0) return false ; if (difference <= 5) return "Just now" ; if (difference <= 20) return "Seconds ago" ; if (difference <= 60) return "A minute ago" ; if (difference < 3600) return parseInt(difference/60)+ " minutes ago" ; if (difference <= 1.5*3600) return "One hour ago" ; if (difference < 23.5*3600) return Math.round(difference/3600)+ " hours ago" ; if (difference < 1.5*24*3600) return "One day ago" ; // If the tweet is older than a day, show an absolute date/time value; var dateArr = pastTime.split( ' ' ); return dateArr[4].replace(/\:\d+$/, '' )+ ' ' +dateArr[2]+ ' ' +dateArr[1]+ (dateArr[3]!=curDate.getFullYear()? ' ' +dateArr[3]: '' ); } |
ConversionConversion EmoticonEmoticon