AO3: highlight tags

Configure tags to be highlighted with different colors - please install V2 of this script instead

  1. // ==UserScript==
  2. // @name AO3: highlight tags
  3. // @description Configure tags to be highlighted with different colors - please install V2 of this script instead
  4. // @namespace http://greasyfork.org/users/6872-fangirlishness
  5. // @author Fangirlishness
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
  7. // @include http://archiveofourown.org/*
  8. // @include https://archiveofourown.org/*
  9. // @grant none
  10. // @version 1.1
  11. // ==/UserScript==
  12.  
  13. // loosely derived from tuff-ghost's ao3 hide some tags (with permission)
  14.  
  15. (function($) {
  16.  
  17. /**** CONFIG ********************/
  18.  
  19. // add the tag pattern you want to highlight (can appear anywhere in the tag) and the color for each
  20. var tagsToHighlight = {"Alternate Universe":"#fda7d1", // pink
  21. "Fanart":"#adf7d1", // light green
  22. "Mpreg.*":"red", // regexp patterns can be used
  23. "somethingelse": "blue"}; // named colors work too
  24.  
  25. /********************************/
  26. $('.blurb ul.tags, .meta .tags ul').each(function() {
  27. var $list = $(this);
  28. $list.find('a.tag').each(function() {
  29. var $tag = $(this);
  30. var text = $tag.text();
  31. for (var key in tagsToHighlight) {
  32. var pattern = new RegExp(key, "g")
  33. if(text.match(pattern) != null) {
  34. highlightTag($tag, tagsToHighlight[key]);
  35. }
  36. }
  37. });
  38. });
  39.  
  40. function highlightTag($tag, color) {
  41. $tag.css('background-color', color);
  42. }
  43. })(jQuery);