linkingpaths (owner)

Revisions

gist: 40117 Download_button fork
public
Public Clone URL: git://gist.github.com/40117.git
Embed All Files: show embed
JavaScript #
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
// Smart way to find the username of a visitor. Published by http://dcortesi.com/tools/my-first-follow/
 
function docoolstuff(username) {
  $.getJSON("http://twitter.com/statuses/user_timeline.json?count=1&callback=?",
    function(data){
      if (username){
        username = username;
        var greeting = "@"+username+"'s ";
        var ref = " they ";
        var tweet = "The first person @"+username+" followed was @";
      } else {
        username = data[0].user.screen_name;
        var greeting = "Hi, @"+username+". Your ";
        var ref = " you ";
        var tweet = "The first person I followed on Twitter was @";
      }
      $.getJSON("http://twitter.com/users/show/"+username+".json?callback=?",
        function(data){
          var pages = Math.ceil((data.friends_count/100));
          $.getJSON("http://twitter.com/statuses/friends/"+username+".json?page="+pages+"&callback=?",
            function(data){
              var link = "http://twitter.com/home?status="+tweet+data[data.length-1].screen_name+". http://dcortesi.com/tools/my-first-follow/";
              $("#followtext").html(greeting +"first follow (that"+ref+"still follow) was <strong>@"+data[data.length-1].screen_name+"</strong>. [<a href=\""+link+"\">Tweet this</a>]");
              $("#username").val(data[data.length-1].screen_name);
            }
          );
        }
      );
    }
  );
}
 
$(document).ready(function(){
  docoolstuff()
});