Hovercard follows

Te dice si un usuario te sigue en la hovercard

  1. // ==UserScript==
  2. // @name Hovercard follows
  3. // @namespace https://www.taringa.net/rata__7
  4. // @version 0.4
  5. // @description Te dice si un usuario te sigue en la hovercard
  6. // @author Nezumi
  7. // @match *://www.taringa.net/*
  8. // ==/UserScript==
  9.  
  10. // Se utiliza la funcion waitUntilExist que se agrega a jQuery para que cada hovercard pueda procesarse a medida que aparecen
  11.  
  12. ;(function ($, window) {
  13. var intervals = {};
  14. var removeListener = function(selector) {
  15. if (intervals[selector]) {
  16. window.clearInterval(intervals[selector]);
  17. intervals[selector] = null;
  18. }
  19. };
  20. var found = 'waitUntilExists.found';
  21. $.fn.waitUntilExists = function(handler, shouldRunHandlerOnce, isChild) {
  22. var selector = this.selector;
  23. var $this = $(selector);
  24. var $elements = $this.not(function() { return $(this).data(found); });
  25. if (handler === 'remove') {
  26. // Hijack and remove interval immediately if the code requests
  27. removeListener(selector);
  28. } else {
  29. // Run the handler on all found elements and mark as found
  30. $elements.each(handler).data(found, true);
  31. if (shouldRunHandlerOnce && $this.length) {
  32. // Element was found, implying the handler already ran for all
  33. // matched elements
  34. removeListener(selector);
  35. } else if (!isChild) {
  36. // If this is a recurring search or if the target has not yet been
  37. // found, create an interval to continue searching for the target
  38. intervals[selector] = window.setInterval(function () {
  39. $this.waitUntilExists(handler, shouldRunHandlerOnce, true);
  40. }, 250);
  41. }
  42. }
  43. return $this;
  44. };
  45. }(jQuery, window));
  46.  
  47. //Acá empieza mi código
  48. var getSeguidores = function(id){
  49. console.log("Buscando seguidores...");
  50. var seguidores = {};
  51. var page = 1;
  52. var ok=true;
  53. while(ok){
  54. $.get('https://api.taringa.net/user/followers/view/' + id + '?trim_user=true&count=50&page='+ page, function(data){
  55. if(data.length > 0){
  56. data.forEach(function(u){
  57. seguidores[u] = true;
  58. });
  59. page++;
  60. } else {
  61. console.log("Fin seguidores");
  62. ok = false;
  63. }
  64. });
  65. }
  66. return seguidores;
  67. };
  68.  
  69. var getTooltipUserId = function(tooltip){
  70. var str = tooltip.attr("class");
  71. str = str.substr(0,str.indexOf(' '));
  72. return parseInt(str.slice(10));
  73. };
  74.  
  75. var tooltipUserFollowsMe = function(id){
  76. return typeof h_followers[id.toString()] !== 'undefined';
  77. };
  78.  
  79. var hovercardFollows = function(){
  80. $(".tooltip-wrapper-v6").waitUntilExists(function(){
  81. var id = getTooltipUserId($(this));
  82. if(tooltipUserFollowsMe(id)){
  83. $('.user-status',$(this)).prepend('<span>Está siguiéndote</span>');
  84. }
  85. });
  86. };
  87.  
  88. var h_nick = $('.user-name').html();
  89. if(h_nick !== null){
  90. $.ajaxSetup({
  91. async: false
  92. });
  93. var h_followers = JSON.parse(localStorage.getItem("seguidores"));
  94. var lastFollowersCall = localStorage.getItem("seguidoresTime");
  95. var hoy = new Date();
  96. var limite = 1000*60*60*2; // 2 horas para recargar seguidores
  97. if(h_followers === null || lastFollowersCall === null || (hoy-Date.parse(lastFollowersCall)) > limite){
  98. h_followers = getSeguidores(global_data.user);
  99. localStorage.setItem("seguidores", JSON.stringify(h_followers));
  100. localStorage.setItem("seguidoresTime", hoy);
  101. console.log("Seguidores guardados :)");
  102. }
  103. hovercardFollows();
  104. }