ao3 hide some tags

Auto hide some tags you don't like to see

目前为 2015-03-04 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name ao3 hide some tags
  3. // @description Auto hide some tags you don't like to see
  4. // @namespace ao3
  5. // @include http*://archiveofourown.org/*
  6. // @grant none
  7. // @version 1.1
  8. // ==/UserScript==
  9.  
  10.  
  11. (function($) {
  12.  
  13.  
  14. /**** CONFIG ********************/
  15.  
  16. var tagsToHide = ["camel spiders", "*worms", "ticks"]; // use * for wildcard
  17. var buttonLabel = "~";
  18.  
  19. /********************************/
  20.  
  21.  
  22.  
  23.  
  24. $('.blurb ul.tags, .meta .tags ul').each(function() {
  25. var $list = $(this);
  26. $list.find('a.tag').each(function() {
  27. var $tag = $(this);
  28. var text = $tag.text();
  29. for (var i = 0, len = tagsToHide.length; i < len; i++) {
  30. if (termsMatch(text, tagsToHide[i])) {
  31. hideTagsList($list);
  32. return false;
  33. }
  34. }
  35. });
  36. });
  37.  
  38. function hideTagsList($list) {
  39. $list.hide();
  40. $('<button>').addClass('hide-some-tags-userscript').text(buttonLabel).click(function() {
  41. $(this).next('ul').toggle();
  42. }).insertBefore($list);
  43. }
  44. function termsMatch(testTerm, listTerm) {
  45. testTerm = testTerm.toLowerCase();
  46. listTerm = listTerm.toLowerCase();
  47. if (testTerm == listTerm) { return true; }
  48.  
  49. if (listTerm.indexOf('*') == -1) return false;
  50. var parts = listTerm.split('*'),
  51. prevPartIndex = 0,
  52. firstPart,
  53. lastPart;
  54.  
  55. for (var i = 0, part, len = parts.length; i < len; i++) {
  56. part = parts[i];
  57. partIndex = testTerm.indexOf(part);
  58. if (part && partIndex < prevPartIndex) {
  59. return false;
  60. }
  61. prevPartIndex = partIndex + part.length;
  62. }
  63. firstPart = parts[0];
  64. lastPart = parts[parts.length-1];
  65.  
  66. return !(
  67. firstPart && testTerm.indexOf(firstPart) != 0 ||
  68. lastPart && testTerm.indexOf(lastPart)+lastPart.length != testTerm.length
  69. );
  70. }
  71.  
  72. })(window.jQuery);