MeFi Hover Favorites

Show who favorited a comment by hovering over it

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name       MeFi Hover Favorites
// @namespace  http://www.roufa.com/
// @version    0.15
// @description  Show who favorited a comment by hovering over it
// @match      http://*.metafilter.com/*/*
// @resource   jquicss   http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css
// @require    http://code.jquery.com/ui/1.10.3/jquery-ui.js
// ==/UserScript==

$(function() {
    var newCSS = GM_getResourceText ("jquicss");
    GM_addStyle (newCSS);
    GM_addStyle (".ui-tooltip {font-size:10pt;font-family:Calibri;}");

    var titles = {};
    $('div#page').on('mouseover', 'span[id^="favcnt"] a', function(evt) {
    	var link = evt.target;
        var href = link.href;
        if (titles[href]) return;
        link.title = '';
        titles[href]=true;
        $.get(href, null, function(d) {
        	var output = '';
            $('a', '<div>' + d.split('<div class="copy">')[1].split('</div>')[0] + '</div>').each(function(ix, el) { output += el.innerText + ', '; });
            output = output.substr(0, output.length-2);
            link.title = output;
            $(link).tooltip({content: output});
            $(link).tooltip("open");
        });
    });
    
    // [Add to] / [remove from] favorites (main post)
    $('div.copy').on('click', 'span[id^="fav"] a:eq(0)', function(evt){ // need to use the first one as there's no id or class for the add-to-favorites link (until AFTER it's been clicked once)
        var href = $('div.copy span[id^="favcnt"] a').attr('href');
        titles[href] = false;
    });

    // +/- button for comments
    $('div#page').on('click', 'a[id^="plusminus"]', function(evt){
        var favcntid = 'favcnt' + evt.target.id.split('plusminus')[1];
        var ancs = $('span#' + favcntid + ' a');
        if (ancs[0]) {
        	titles[ancs[0].href] = false;
        }
    });
});