ao3 tags savior

hide works with too many tags on the AO3

  1. // ==UserScript==
  2. // @name ao3 tags savior
  3. // @description hide works with too many tags on the AO3
  4. // @namespace ao3
  5. // @include http*://archiveofourown.org/*
  6. // @grant none
  7. // @version 1.0
  8. // ==/UserScript==
  9.  
  10. // based on Tegan's Crossover savior: https://greasyfork.org/en/scripts/13274-ao3-crossover-savior
  11.  
  12. /**** CONFIG ********************/
  13. window.ao3TagsConfig = {
  14. maxTags: 15,
  15. // set to the maximum number of tags per work you want to see
  16. // keep in mind that this number is count of all tags: fandoms, relationships, characters and freeform
  17. // so you may want to keep this number relatively high
  18. };
  19. /********************************/
  20.  
  21. (function($) {
  22.  
  23. var works = $('li.blurb');
  24. if (!works[0]) return;
  25.  
  26. var toggleClass = 'ao3-tags-hide-toggle',
  27. fold = $('<p>').addClass('fold').append(
  28. $('<span>').addClass(toggleClass).text('This work is hidden! '),
  29. $('<span>').addClass(toggleClass).html('This work was hidden. ').hide(),
  30. $('<span>').addClass('reason'),
  31. $('<span>').addClass('actions').append(
  32. $('<a>').addClass('action').css({
  33. 'position': 'absolute',
  34. 'right': 8,
  35. 'top': 10
  36. }).text('Unhide')
  37. )
  38. ),
  39. bl = window.ao3TagsConfig,
  40. shouldBlacklist = function(work) {
  41. var tag = work.find('a.tag');
  42. if (tag.length > bl.maxTags) {
  43. return tag.length;
  44. }
  45. },
  46. blacklist = function(work, reason) {
  47. var cut = $('<div>').addClass('cut').html(work.html()),
  48. reason = '(Too many tags: ' + reason +')',
  49. thisFold = fold.clone(),
  50. reasonContainer = thisFold.find('.reason');
  51.  
  52. reasonContainer.html(reason);
  53.  
  54. work.empty().append(thisFold, cut.hide());
  55. work.find('a.action').click(function() {
  56. var fold = $(this).closest('.fold'),
  57. cut = fold.next('.cut');
  58.  
  59. cut.add(fold.children('.'+toggleClass)).toggle();
  60. $(this).text(cut.is(':visible') ? 'Hide' : 'Unhide');
  61. });
  62. };
  63.  
  64. works.each(function() {
  65. var reason = shouldBlacklist($(this));
  66. if (reason) {
  67. blacklist($(this), reason);
  68. }
  69. });
  70.  
  71. })(window.jQuery);