EH – SearchNav Click UI

Make SearchNav more mouse-friendly; also easier method to search by date

Verze ze dne 05. 11. 2022. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name EH – SearchNav Click UI
  3. // @namespace fabulous.cupcake.jp.net
  4. // @version 2022.11.05.1
  5. // @description Make SearchNav more mouse-friendly; also easier method to search by date
  6. // @author FabulousCupcake (the one who made it), JoGaTo (the uploader)
  7. // @license MIT
  8. // @runat document-start
  9. // @include /https?:\/\/(e-|ex)hentai\.org\/.*/
  10. // @grant unsafeWindow
  11. // ==/UserScript==
  12.  
  13. const stylesheet = `
  14. #ujumpbox {
  15. position: relative;
  16. }
  17. #ujumpbox .preset-inputs {
  18. display: flex;
  19. flex-direction: column;
  20. gap: 4px;
  21. padding: 0.5em;
  22. position: absolute;
  23. top: 30px;
  24. left: 50%;
  25. transform: translateX(-50%);
  26. z-index: 99999;
  27. }
  28. #ujumpbox .row {
  29. display: flex;
  30. flex-direction: row;
  31. justify-content: center;
  32. }
  33. #ujumpbox .preset-inputs input {
  34. width: 33px;
  35. }
  36. /* Date Input Width Fix */
  37. .jumpbox { width: auto !important; }
  38. `;
  39.  
  40. const hasSearchNav = () => {
  41. return !!document.querySelector(".searchnav");
  42. }
  43.  
  44. const addStylesheet = () => {
  45. const stylesheetEl = document.createElement("style");
  46. stylesheetEl.innerHTML = stylesheet;
  47. document.body.appendChild(stylesheetEl);
  48. }
  49.  
  50. const addElements = () => {
  51. const hook = document.querySelector("#ujumpbox");
  52. const el = `
  53. <div class="preset-inputs stuffbox">
  54. <div class="row" style="margin-bottom: 0.25em;">
  55. <button class="date-input">Use Date Input</button>
  56. </div>
  57. <div class="row">
  58. <input type="button" value="1d"/>
  59. <input type="button" value="3d"/>
  60. <input type="button" value="1w"/>
  61. <input type="button" value="2w"/>
  62. </div>
  63. <div class="row">
  64. <input type="button" value="1m"/>
  65. <input type="button" value="6m"/>
  66. <input type="button" value="1y"/>
  67. <input type="button" value="2y"/>
  68. </div>
  69. </div>
  70. `;
  71. hook.insertAdjacentHTML("beforeend", el);
  72. }
  73.  
  74. const addEventListeners = () => {
  75. // Preset Button Events
  76. const presetInputButtons = document.querySelectorAll("#ujumpbox .preset-inputs input");
  77. const handler = e => {
  78. const mainInput = document.querySelector("#ujump");
  79. const value = e.target.getAttribute("value");
  80.  
  81. mainInput.value = value;
  82. mainInput.dispatchEvent(new Event('change'));
  83. }
  84.  
  85. Array.from(presetInputButtons).forEach(el => el.addEventListener("click", handler));
  86.  
  87. // Date Input Event
  88. const dateButton = document.querySelector("#ujumpbox .date-input");
  89. dateButton.addEventListener("click", () => {
  90. const mainInput = document.querySelector("#ujump");
  91. mainInput.setAttribute("type", "date");
  92.  
  93. // Disable preset inputs
  94. Array.from(presetInputButtons).forEach(el => el.setAttribute("disabled", ""));
  95. });
  96. }
  97.  
  98. const addSearchJumpButtonCallback = callbackFn => {
  99. const origFn = unsafeWindow.enable_jump_mode;
  100. unsafeWindow.enable_jump_mode = function() {
  101. origFn.apply(this, arguments);
  102. callbackFn();
  103. }
  104. }
  105.  
  106. const main = () => {
  107. if (!hasSearchNav()) return;
  108. addStylesheet();
  109.  
  110. addSearchJumpButtonCallback(() => {
  111. addElements();
  112. addEventListeners();
  113. });
  114. }
  115.  
  116. main();
  117.  
  118.