Advertisement
Guest User

Akun FollowMap

a guest
Apr 17th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // Displayable Name of your script
  3. // @name           Akun FollowMap
  4.  
  5. // Brief description
  6. // @description    Playing around with svgs and data
  7.  
  8. // Version Number
  9. // @version        1
  10.  
  11. // @include          https://anonkun.com/user
  12. // @include          http://anonkun.com/user
  13.  
  14. //@require           https://raw.githubusercontent.com/adobe-webplatform/Snap.svg/master/dist/snap.svg-min.js
  15.  
  16. // ==/UserScript==
  17. console.log("Followmap active!");
  18.  
  19. $(document).ready(function(){
  20.     $('body').children().remove(); // Clear the space
  21.     $('head').after('<style type="text/css" id="FollowMap-css"></style>'); // Insert the FollowMap style element
  22.     $('#FollowMap-css').append('g{opacity:1}html{overflow-y: auto;}.fullscreen{position: fixed; height:100%; width:100%;}#svg{position:relative; top:0px; left:0px; height:100px; width:100px; overflow:visible;}circle{fill: rgb(215, 109, 37); stroke: white; stroke-width: 1px}line{stroke: white; stroke-width: 1px}');
  23.     $('body').append('<div class="fullscreen" style="display:flex; justify-content: center; align-items: center;"><form id="UsernameForm" onsubmit="return false;"><input id="UsernameInput" type="text" autofocus placeholder="Enter username" style="width:300px; height:31px;"></form></div>');
  24.     $('#UsernameForm').on("submit", function(){
  25.         var username = $('#UsernameInput')[0].value.toLowerCase();
  26.         $.ajax({
  27.             url: "http://anonkun.com/api/user/"+encodeURI(username)
  28.         }).done(function(response){
  29.             if (response.username === undefined){
  30.                 $('#UsernameForm').append('<div style="position:relative; height:0px;">Username not found</div>');
  31.                 $('#UsernameForm > :last-child').fadeOut(600, function(){
  32.                     $(this).remove();
  33.                 });
  34.             }else{
  35.                 $('.fullscreen').html('<svg id="svg"></svg>');
  36.                 var s = Snap("#svg");
  37.                 s.g().attr({id:'u-'+response._id, transform:"translate(50, 50)"});
  38.                 $('g#u-'+response._id).html('<a xlink:href="http://anonkun.com/user/'+encodeURI(username)+'"><circle cx="0" cy="0" r="5"></circle></a>');
  39.                 //$('g#u-'+response._id).html('<a xlink:href="http://anonkun.com/user/'+encodeURI(username)+'"></a>');
  40.                 //$('g#u-'+response._id+'>a').html('<circle cx="0" cy="0" r="5"></circle>');
  41.                 //Snap('g#u-'+response._id).circle(0,0,5);
  42.                 obj[response._id] = {"username":username, "followersChecked":false, "followingChecked":false, "followers":[], "following":[]};
  43.                 addFollowers(response._id);
  44.                 //addFollowing(username);
  45.                 clickToDrag();
  46.             }
  47.         });
  48.     });
  49. });
  50.  
  51. function clickToDrag(){
  52.     var oldX = 0;
  53.     var oldY = 0;
  54.     $(document).on("mousedown", function(e){
  55.         oldX = parseInt($('#svg').css('left')) - e.clientX;
  56.         oldY = parseInt($('#svg').css('top')) - e.clientY;
  57.         $(document).on("mousemove", function(e){
  58.             $('#svg').css({
  59.                 "left":oldX + e.clientX,
  60.                 "top":oldY + e.clientY
  61.             });
  62.         });
  63.     });
  64.     $(document).on("mouseup", function(){
  65.         $(document).off("mousemove");
  66.     });
  67. }
  68.  
  69. var obj = {};
  70. var CountIng = 0;
  71. var CountErs = 0;
  72.  
  73. function addFollowers(id){
  74.     CountErs++;
  75.     //if(CountErs > 5){return;}
  76.     obj[id].followersChecked = true;
  77.     $.ajax({
  78.         url: "http://anonkun.com/api/anonkun/followers/"+id // Get its followers list
  79.     }).done(function(response){
  80.         $('g#u-'+id+' > a > circle').attr('r',(response.length/2)+5);
  81.         var angle = 2*Math.PI/response.length;
  82.         var lengthFollower = 20+(3*response.length);
  83.  
  84.         if (response.length && $('g#u-'+id).data('angle') !== undefined){
  85.             var oldAngle = $('g#u-'+id).data('angle');
  86.             var oldLengthFollower = $('g#u-'+id).data('lengthFollower');
  87.             var newLengthFollower = oldLengthFollower + 2*lengthFollower;
  88.             var newX = Math.round(newLengthFollower * Math.sin(oldAngle) * 10000) / 10000;
  89.             var newY = Math.round(newLengthFollower * Math.cos(oldAngle) * 10000) / 10000;
  90.             $('g#u-'+id)[0].transform.baseVal[0].matrix.e = newX;
  91.             $('g#u-'+id)[0].transform.baseVal[0].matrix.f = newY;
  92.             $('#l-'+id).attr({'x2':newX,'y2':newY});
  93.         }
  94.         //console.log(angle);
  95.         $.each(response, function(i,v){
  96.             //window.setTimeout(function(){
  97.             obj[id].followers.push(v._id);
  98.             if (obj[v._id] === undefined){
  99.                 obj[v._id] = {"username":v.username, "followersChecked":false, "followingChecked":false, "followers":[], "following":[]};
  100.             }
  101.  
  102.             if (!$('g#u-'+v._id).length){
  103.                 var x = lengthFollower * Math.sin(angle*i);
  104.                 var y = lengthFollower * Math.cos(angle*i);
  105.                 x = Math.round(x * 10000) / 10000; // Stop the issues that ~0 values cause
  106.                 y = Math.round(y * 10000) / 10000;
  107.                 Snap('g#u-'+id).line(Math.round(((response.length/2)+5) * Math.sin(angle*i) * 10000) / 10000,Math.round(((response.length/2)+5) * Math.cos(angle*i) * 10000) / 10000,x,y).attr({id:'l-'+v._id});
  108.                 Snap('g#u-'+id).g().attr({id:'u-'+v._id, transform:'translate('+x+', '+y+')'});
  109.                 //$('g#u-'+id).prepend('<line x1="0" y1="0" x2="200" y2="200"/>');
  110.                 $('g#u-'+v._id).data({'angle':angle*i, 'lengthFollower':lengthFollower});
  111.                 //Snap('g#u-'+v._id).circle(0,0,5);
  112.                 $('g#u-'+v._id).html('<a xlink:href="http://anonkun.com/user/'+encodeURI(v.username)+'"><circle cx="0" cy="0" r="5"></circle></a>');
  113.             }else{
  114.                 x = 0;
  115.                 y = 0;
  116.                 //Snap('g#u-'+id).line(Math.round(((response.length/2)+5) * Math.sin(angle*i) * 10000) / 10000,Math.round(((response.length/2)+5) * Math.cos(angle*i) * 10000) / 10000,x,y).attr({id:'l-'+v._id});
  117.             }
  118.  
  119.             if (!obj[v._id].followersChecked){
  120.                 addFollowers(v._id);
  121.             }
  122.             if (!obj[v._id].followingChecked){
  123.                 //addFollowing(v._id);
  124.             }
  125.             //},1000);
  126.         });
  127.         //console.log(obj);
  128.     });
  129. }
  130.  
  131. function addFollowing(username){
  132.     CountIng++;
  133.     if(CountIng > 5){return;}
  134.     obj[username].followingChecked = true;
  135.     $.ajax({
  136.         url: "http://anonkun.com/api/anonkun/following/"+obj[username].id // Get its followers list
  137.     }).done(function(response){
  138.         $.each(response, function(i,v){
  139.             obj[username].following.push(v.username);
  140.             if (obj[v.username] === undefined){
  141.                 obj[v.username] = {"id":v._id, "followersChecked":false, "followingChecked":false, "followers":[], "following":[]};
  142.             }
  143.             if (!obj[v.username].followersChecked){
  144.                 addFollowers(v.username);
  145.             }
  146.             if (!obj[v.username].followingChecked){
  147.                 addFollowing(v.username);
  148.             }
  149.         });
  150.         //console.log(obj);
  151.     });
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement