RamisAmuki-Utils

RamisAmuki Utils.

目前為 2023-09-18 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/469263/1252431/RamisAmuki-Utils.js

  1. // ==UserScript==
  2. // @name RamisAmuki-Utils
  3. // @description RamisAmuki Utils.
  4. // @author RamisAmuki
  5. // @grant none
  6. // ==/UserScript==
  7.  
  8. function check_rate_price(liqs, querys) {
  9. const li_rate_node = liqs(querys.rate);
  10. const li_rate = li_rate_node != null ? parseInt(li_rate_node.innerText) : 0;
  11. const li_price = parseInt(liqs(querys.price).innerText.replace(",", ""));
  12. let base_rate = Number(localStorage.getItem("rate-input") || 90);
  13. let base_price = Number(localStorage.getItem("price-input") || 100);
  14. const result_array = [li_rate < base_rate, li_price > base_price];
  15. if (checkboxEnable("toggle-and-or")) {
  16. return result_array.some((b) => b);
  17. }
  18. return result_array.every((b) => b); // 現状はNAND検索 = OR検索
  19. }
  20.  
  21. function disabling(li) {
  22. li.style.display = "none";
  23. }
  24.  
  25. function enabling(li) {
  26. li.style.display = "";
  27. }
  28.  
  29. function all_enable(querys) {
  30. document.querySelectorAll(querys.lists).forEach((li) => enabling(li));
  31. }
  32.  
  33. function filter(checker, querys) {
  34. document.querySelectorAll(querys.lists).forEach((li) => {
  35. checker((q) => li.querySelector(q)) ? disabling(li) : enabling(li);
  36. });
  37. }
  38.  
  39. function appendButton(
  40. onclick,
  41. querys,
  42. innerHTML = "Filter",
  43. margin = null,
  44. float = "right",
  45. height = "30px",
  46. color = "#000",
  47. backgroundColor = "#f6dbae"
  48. ) {
  49. // ボタン要素を作成
  50. const btn = document.createElement("button");
  51. const label = document.createElement("label");
  52.  
  53. // ボタンを装飾
  54. btn.innerHTML = innerHTML;
  55. btn.id = innerHTML + "-btn";
  56. btn.style.float = float;
  57. btn.style.height = height;
  58. btn.style.color = color;
  59. btn.style.backgroundColor = backgroundColor;
  60. if (margin != null) btn.style.margin = margin;
  61.  
  62. // 実行する関数
  63. btn.onclick = onclick;
  64.  
  65. // ボタンを追加
  66. document.querySelector(querys.button_parent).appendChild(label);
  67. label.appendChild(btn);
  68. }
  69.  
  70. function appendFilterButton(
  71. checker,
  72. querys,
  73. margin = null,
  74. innerHTML = "Filter",
  75. float = "right",
  76. height = "30px",
  77. color = "#000",
  78. backgroundColor = "#f6dbae"
  79. ) {
  80. appendButton(
  81. () => filter(checker, querys),
  82. querys,
  83. innerHTML,
  84. margin,
  85. float,
  86. height,
  87. color,
  88. backgroundColor
  89. );
  90. }
  91.  
  92. function appendRatePriceInput(querys) {
  93. appendInput(querys, "rate", 99, 0, 90);
  94. appendInput(querys, "price", null, 1, 100, "100px");
  95. appendToggleAndOrButton(querys, "false");
  96. }
  97.  
  98. function appendInput(querys, text, max, min, default_val, width = "55px") {
  99. const input = document.createElement("input");
  100. const label = document.createElement("label");
  101.  
  102. input.type = "number";
  103. input.id = text + "-input";
  104. if (max != null) input.max = max;
  105. input.min = min;
  106. input.step = 1;
  107. input.style.width = width;
  108. input.value = localStorage.getItem(input.id) || default_val; // nullだった場合、初期値にする
  109. input.onchange = () => {
  110. localStorage.setItem(input.id, input.value);
  111. document.querySelector("#Filter-btn").click();
  112. };
  113. label.htmlFor = input.id;
  114. label.style.fontSize = "13px";
  115. label.style.maxWidth = "150px";
  116. label.style.marginLeft = label.style.marginRight = "5px";
  117. label.innerText = text + " : ";
  118.  
  119. document.querySelector(querys.button_parent).appendChild(label);
  120. label.appendChild(input);
  121. }
  122.  
  123. function appendToggleButton(querys, text, default_val) {
  124. const input = document.createElement("input");
  125. const label = document.createElement("label");
  126.  
  127. input.type = "checkbox";
  128. input.id = text + "-checkbox";
  129. input.checked = JSON.parse(localStorage.getItem(input.id) || default_val);
  130. input.onchange = () => {
  131. localStorage.setItem(input.id, input.checked);
  132. document.querySelector("#Filter-btn").click();
  133. };
  134. label.htmlFor = input.id;
  135. label.style.fontSize = "13px";
  136. label.style.maxWidth = "150px";
  137. label.style.marginLeft = label.style.marginRight = "5px";
  138. label.innerText = text + " : ";
  139.  
  140. document.querySelector(querys.button_parent).appendChild(label);
  141. label.appendChild(input);
  142. }
  143.  
  144. function appendToggleAndOrButton(querys, default_val) {
  145. const container = document.createElement("div");
  146. container.className = "switch-container";
  147. const label = document.createElement("label");
  148. label.className = "switch";
  149. const input = document.createElement("input");
  150. input.type = "checkbox";
  151. input.id = "toggle-and-or-checkbox";
  152. input.className = "switch-input";
  153. const span = document.createElement("span");
  154. span.className = "switch-label";
  155. span.innerHTML =
  156. '<span class="switch-text switch-and">AND</span><span class="switch-text switch-or">OR</span>';
  157. input.checked = JSON.parse(localStorage.getItem(input.id) || default_val);
  158. input.onchange = () => {
  159. localStorage.setItem(input.id, input.checked);
  160. document.querySelector("#Filter-btn").click();
  161. };
  162. label.htmlFor = input.id;
  163. document.querySelector(querys.button_parent).appendChild(label);
  164. label.appendChild(input);
  165. label.appendChild(span);
  166. const css = `
  167. // .switch-container {
  168. // display: flex;
  169. // align-items: center;
  170. // }
  171.  
  172. .switch {
  173. display: inline-block;
  174. // width: fit-content;
  175. // position: relative;
  176. }
  177.  
  178. .switch-input {
  179. display: none;
  180. }
  181.  
  182. .switch-label {
  183. display: flex;
  184. // align-items: center;
  185. // justify-content: space-between;
  186. }
  187.  
  188. .switch-text {
  189. // width: fit-content;
  190. padding: 0 4px;
  191. // text-align: center;
  192. // font-size: 13px;
  193. }
  194.  
  195. .switch-input:checked + .switch-label .switch-and, .switch-input:not(:checked) + .switch-label .switch-or {
  196. background-color: #2196F3;
  197. color: white;
  198. }
  199.  
  200. .switch-input:checked + .switch-label .switch-or, .switch-input:not(:checked) + .switch-label .switch-and {
  201. background-color: #ccc;
  202. }
  203. `;
  204. const style = document.createElement("style");
  205. style.appendChild(document.createTextNode(css));
  206. document.head.appendChild(style);
  207. }
  208.  
  209. function checkboxEnable(text) {
  210. return JSON.parse(localStorage.getItem(text + "-checkbox"));
  211. }
  212.  
  213. function waitForElement(selector, callback, intervalMs, timeoutMs) {
  214. const startTimeInMs = Date.now();
  215. findLoop();
  216.  
  217. function findLoop() {
  218. if (document.querySelector(selector) != null) {
  219. callback();
  220. return;
  221. } else {
  222. setTimeout(() => {
  223. if (timeoutMs && Date.now() - startTimeInMs > timeoutMs) return;
  224. findLoop();
  225. }, intervalMs);
  226. }
  227. }
  228. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址