ExhTagHighlight

Highlight tags in gallery view according to 'My Tags' config in gallery for Exhentai and Ehentai

  1. // ==UserScript==
  2. // @name ExhTagHighlight
  3. // @version 1.0
  4. // @description Highlight tags in gallery view according to 'My Tags' config in gallery for Exhentai and Ehentai
  5. // @author Caca ductile
  6. // @match https://exhentai.org/g/*
  7. // @match https://exhentai.org/mytags
  8. // @match https://e-hentai.org/g/*
  9. // @match https://e-hentai.org/mytags
  10. // @license MIT
  11. // @namespace https://greasyfork.org/users/979369
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const STORE_NAME = 'exhtaghighlight-settings';
  18.  
  19. const exportMyTagsConfig = () => {
  20. const tagConfigs = document.querySelector("#usertags_outer");
  21. const config = {};
  22. for (const tagConfig of tagConfigs.children) {
  23. const tagLink = tagConfig.querySelector("a");
  24. if (!tagLink) continue;
  25. const tagName = tagLink.href;
  26. const tagValue = tagLink.firstChild.style.cssText;
  27. console.log(tagName, tagValue);
  28. config[tagName] = tagValue;
  29. }
  30. localStorage.setItem(STORE_NAME, JSON.stringify(config));
  31. };
  32.  
  33. const appendExportButton = () => {
  34. document.querySelector("#tagsave").parentElement.insertAdjacentHTML('afterend', '<div><input type="button" id="tagExport" style="margin: 2px 2px 2px 4px;" value="Export"></div>');
  35. document.querySelector("#tagExport").addEventListener("click", exportMyTagsConfig);
  36. };
  37.  
  38. const highlightTags = () => {
  39. const stringConfig = localStorage.getItem(STORE_NAME);
  40. if (!stringConfig) {
  41. console.warn("ExhTagHighlight : Go to 'My Tags' page and hit the export button to save tag config to cache in order for the script to work properly");
  42. return;
  43. }
  44. const config = JSON.parse(stringConfig);
  45. for (const [tag, tagValue] of Object.entries(config)) {
  46. const element = document.querySelector('#taglist a[href="' + tag + '"]');
  47. if (element) {
  48. element.parentElement.style = tagValue;
  49. }
  50. }
  51. };
  52.  
  53. if (window.location.pathname === "/mytags" ) {
  54. appendExportButton();
  55. } else {
  56. highlightTags();
  57. }
  58.  
  59. })();