Ghost Trappers Friends Crawler

Makes getting more friends super easy.

  1. // ==UserScript==
  2. // @name Ghost Trappers Friends Crawler
  3. // @version 1.1
  4. // @description Makes getting more friends super easy.
  5. // @author Hazado
  6. // @require https://code.jquery.com/jquery-2.2.2.min.js
  7. // @match *www.ghost-trappers.com/fb/live_feed.php*
  8. // @match *www.ghost-trappers.com/fb/invite_friend_into_team.php*
  9. // @match *www.ghost-trappers.com/fb/scores.php?type=myteam&more=true*
  10. // @grant none
  11. // @namespace https://greasyfork.org/users/149039
  12. // ==/UserScript==
  13. var check = false;
  14. var user = JSON.parse(localStorage.getItem('AddNames'));
  15. var friends = JSON.parse(localStorage.getItem('GhostTrapperFriends'));
  16. if (friends.length > 1000) throw new Error("You have max # of friends, either clear some from your friends list or cancel invites.");
  17. if (user === null) { var user = [];}
  18. else if (user.length > 20 && window.location.href.indexOf("invite_friend_into_team.php") === -1) { window.location.href = "http://www.ghost-trappers.com/fb/invite_friend_into_team.php"; }
  19. if (friends === null && window.location.href.indexOf("scores.php?type=myteam&more=true") == -1) { check = true; var friends = [];}
  20. console.log("Users: "+user.length);
  21. console.log("Friends and Invited Users: "+friends.length);
  22.  
  23. function checkfornames() {
  24. var temp = document.querySelectorAll('span[class*=playerName]');
  25. if (temp !== null && temp !== undefined){
  26. for (i = 0; i < temp.length; i++) {
  27. user.push(temp[i].textContent);
  28. }
  29. var uniqueNames = [];
  30. $.each(user, function(i, el){
  31. if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
  32. });
  33. uniqueNames = uniqueNames.filter(function(val) {
  34. return friends.indexOf(val) == -1;
  35. });
  36. localStorage.setItem('AddNames', JSON.stringify(uniqueNames));
  37. }
  38. }
  39.  
  40. function acceptFriends() {
  41. var temp = document.querySelectorAll('a[class*=acceptTeamRequest]');
  42. if (temp !== null && temp !== undefined){
  43. for (i = 0; i < temp.length; i++) {
  44. var tempsave = temp[i].outerHTML;
  45. tempsave = tempsave.replace("<a class=\"acceptTeamRequest\" onclick=\"acceptTeamRequest(","");
  46. tempsave = tempsave.replace(")\"></a>","");
  47. $.ajax({
  48. type: "POST",
  49. url: 'ajax_invite_friend_into_team.php',
  50. data: 'action=acceptRequest' + '&requestId=' + tempsave,
  51. success: onAcceptOrDeclinedOrCanceledReceived,
  52. dataType: 'json'
  53. });
  54. }
  55. }
  56. filterFriends();
  57. }
  58.  
  59. function filterFriends() {
  60. $(document).ready();
  61. var temp = document.querySelectorAll('span[class*=playerName]');
  62. var tempuser = [];
  63. if (temp !== null && temp !== undefined){
  64. // Add invited users to Friend List
  65. for (i = 0; i < temp.length; i++) {
  66. tempuser.push(temp[i].textContent);
  67. }
  68. $.each(tempuser, function(g, el){
  69. if($.inArray(el, friends) === -1) friends.push(el);
  70. });
  71. // Compare users to add against new friend list
  72. user = user.filter(function(val) {
  73. return friends.indexOf(val) == -1;
  74. });
  75. localStorage.setItem('GhostTrapperFriends', JSON.stringify(friends));
  76. }
  77. addFriends();
  78. }
  79.  
  80. function addFriends() {
  81. // Add new users
  82. var agentName = user.pop();
  83. if (agentName !== undefined) {
  84. $('#inviteRequestMessageContainer').hide();
  85. $.ajax({
  86. type: "POST",
  87. url: 'ajax_invite_friend_into_team.php',
  88. data: 'action=addFriendRequest' + '&agentName=' + agentName,
  89. success: onSendTeamRequestReceived,
  90. dataType: 'json'
  91. });
  92. setTimeout(function() { addFriends(); }, 1000);
  93. localStorage.removeItem('AddNames');
  94. }
  95. // Add users invited to Friend List
  96. else if (agentName === undefined) {
  97. temp = document.querySelectorAll('span[class*=playerName]');
  98. tempuser = [];
  99. if (temp !== null && temp !== undefined){
  100. for (i = 0; i < temp.length; i++) {
  101. tempuser.push(temp[i].textContent);
  102. }
  103. $.each(tempuser, function(i, el){
  104. if($.inArray(el, friends) === -1) friends.push(el);
  105. });
  106. }
  107. window.location.href = "http://www.ghost-trappers.com/fb/live_feed.php";
  108. }
  109. }
  110.  
  111. function setupFriends() {
  112. $(document).ready();
  113. var temp = document.querySelectorAll('span[class*=playerName]');
  114. if (temp !== null && temp !== undefined){
  115. for (i = 0; i < temp.length; i++) {
  116. user.push(temp[i].textContent);
  117. }
  118. var uniqueFriends = [];
  119. $.each(user, function(i, el){
  120. if($.inArray(el, uniqueFriends) === -1) uniqueFriends.push(el);
  121. });
  122. localStorage.setItem('GhostTrapperFriends', JSON.stringify(uniqueFriends));
  123. alert("Friends recorded!");
  124. check = false;
  125. window.location.href = "http://www.ghost-trappers.com/fb/live_feed.php";
  126. }
  127. }
  128. if (check === true){alert("You need to let the Friend page load completely first!");window.location.href = "http://www.ghost-trappers.com/fb/scores.php?type=myteam&more=true";}
  129. else if (window.location.href.indexOf("www.ghost-trappers.com/fb/live_feed.php") != -1) { window.setInterval(checkfornames,1000); }
  130. else if (window.location.href.indexOf("www.ghost-trappers.com/fb/invite_friend_into_team.php") != -1) { acceptFriends(); }
  131. else if (window.location.href.indexOf("www.ghost-trappers.com/fb/scores.php?type=myteam&more=true") != -1) { setTimeout(function() { setupFriends(); },20000); }