MeFi Hover Favorites

Show who favorited a comment by hovering over it

  1. // ==UserScript==
  2. // @name MeFi Hover Favorites
  3. // @namespace http://www.roufa.com/
  4. // @version 0.15
  5. // @description Show who favorited a comment by hovering over it
  6. // @match http://*.metafilter.com/*/*
  7. // @resource jquicss http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css
  8. // @require http://code.jquery.com/ui/1.10.3/jquery-ui.js
  9. // ==/UserScript==
  10.  
  11. $(function() {
  12. var newCSS = GM_getResourceText ("jquicss");
  13. GM_addStyle (newCSS);
  14. GM_addStyle (".ui-tooltip {font-size:10pt;font-family:Calibri;}");
  15.  
  16. var titles = {};
  17. $('div#page').on('mouseover', 'span[id^="favcnt"] a', function(evt) {
  18. var link = evt.target;
  19. var href = link.href;
  20. if (titles[href]) return;
  21. link.title = '';
  22. titles[href]=true;
  23. $.get(href, null, function(d) {
  24. var output = '';
  25. $('a', '<div>' + d.split('<div class="copy">')[1].split('</div>')[0] + '</div>').each(function(ix, el) { output += el.innerText + ', '; });
  26. output = output.substr(0, output.length-2);
  27. link.title = output;
  28. $(link).tooltip({content: output});
  29. $(link).tooltip("open");
  30. });
  31. });
  32. // [Add to] / [remove from] favorites (main post)
  33. $('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)
  34. var href = $('div.copy span[id^="favcnt"] a').attr('href');
  35. titles[href] = false;
  36. });
  37.  
  38. // +/- button for comments
  39. $('div#page').on('click', 'a[id^="plusminus"]', function(evt){
  40. var favcntid = 'favcnt' + evt.target.id.split('plusminus')[1];
  41. var ancs = $('span#' + favcntid + ' a');
  42. if (ancs[0]) {
  43. titles[ancs[0].href] = false;
  44. }
  45. });
  46. });