Hovercard follows

Te dice si un usuario te sigue en la hovercard

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Hovercard follows
// @namespace    https://www.taringa.net/rata__7
// @version      0.3
// @description  Te dice si un usuario te sigue en la hovercard
// @author       Nezumi
// @match        *://www.taringa.net/*
// ==/UserScript==

// Se utiliza la funcion waitUntilExist que se agrega a jQuery para que cada hovercard pueda procesarse a medida que aparecen

;(function ($, window) {
    var intervals = {};
    var removeListener = function(selector) {
    	if (intervals[selector]) {
    		window.clearInterval(intervals[selector]);
    		intervals[selector] = null;
    	}
    };
    var found = 'waitUntilExists.found';
    $.fn.waitUntilExists = function(handler, shouldRunHandlerOnce, isChild) {
    	var selector = this.selector;
    	var $this = $(selector);
    	var $elements = $this.not(function() { return $(this).data(found); });
    	if (handler === 'remove') {
    		// Hijack and remove interval immediately if the code requests
    		removeListener(selector);
    	} else {
    		// Run the handler on all found elements and mark as found
    		$elements.each(handler).data(found, true);
    		if (shouldRunHandlerOnce && $this.length) {
    			// Element was found, implying the handler already ran for all 
    			// matched elements
    			removeListener(selector);
    		} else if (!isChild) {
    			// If this is a recurring search or if the target has not yet been 
    			// found, create an interval to continue searching for the target
    			intervals[selector] = window.setInterval(function () {
    				$this.waitUntilExists(handler, shouldRunHandlerOnce, true);
    			}, 250);
    		}
    	}
    	return $this;
    };
}(jQuery, window));

//Acá empieza mi código
var getSeguidores = function(id){
    console.log("Buscando seguidores...");
    var seguidores = [];
    var page = 1;
    var ok=true;
    while(ok){
      $.get('https://api.taringa.net/user/followers/view/' + id + '?trim_user=true&count=50&page='+ page, function(data){
        if(data.length > 0){
            seguidores.push.apply(seguidores, data);
            page++;
        } else {
            console.log("Fin seguidores");
            ok = false;
        }
      });
    }
    return seguidores;
};

var getTooltipUserId = function(tooltip){
    var str = tooltip.attr("class");
    str = str.substr(0,str.indexOf(' '));
    return parseInt(str.slice(10));
};

var tooltipUserFollowsMe = function(id){
    return h_followers.indexOf(id) != -1;
};

var hovercardFollows = function(){
    $(".tooltip-wrapper-v6").waitUntilExists(function(){
        var id = getTooltipUserId($(this));
        if(tooltipUserFollowsMe(id)){
            $('.user-status',$(this)).prepend('<span>Está siguiéndote</span>');
        }
    });
};

var h_nick = $('.user-name').html();
if(h_nick !== null){
    $.ajaxSetup({
        async: false
    });
    var h_followers = localStorage.getItem("seguidores");
    var lastFollowersCall = localStorage.getItem("seguidoresTime");
    var hoy = new Date();
    var limite = 1000*60*60*2; // 2 horas para recargar seguidores
    if(h_followers === null || lastFollowersCall === null || (hoy-Date.parse(lastFollowersCall)) > limite){
        h_followers = getSeguidores(global_data.user);
        localStorage.setItem("seguidores", h_followers);
        localStorage.setItem("seguidoresTime", hoy);
        console.log("Seguidores guardados :)");
    }
    hovercardFollows();
}