Hovercard follows

Te dice si un usuario te sigue en la hovercard

目前為 2016-12-19 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Hovercard follows
  3. // @namespace https://www.taringa.net/rata__7
  4. // @version 0.1
  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. }, 500);
  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. seguidores.push.apply(seguidores, data);
  57. page++;
  58. } else {
  59. console.log("Fin seguidores");
  60. ok = false;
  61. }
  62. });
  63. }
  64. return seguidores;
  65. };
  66.  
  67. var getTooltipUserId = function(tooltip){
  68. var str = tooltip.attr("class");
  69. str = str.substr(0,str.indexOf(' '));
  70. return parseInt(str.slice(10));
  71. };
  72.  
  73. var tooltipUserFollowsMe = function(id){
  74. return h_followers.indexOf(id) != -1;
  75. };
  76.  
  77. var hovercardFollows = function(){
  78. $(".tooltip-wrapper-v6").waitUntilExists(function(){
  79. var id = getTooltipUserId($(this));
  80. if(tooltipUserFollowsMe(id)){
  81. $('.user-status',$(this)).prepend('<span>Está siguiéndote</span>');
  82. }
  83. });
  84. };
  85.  
  86. var h_nick = $('.user-name').html();
  87. if(h_nick !== null){
  88. $.ajaxSetup({
  89. async: false
  90. });
  91. var h_followers = getSeguidores(global_data.user);
  92. hovercardFollows();
  93. }