- // ==UserScript==
- // @name RamisAmuki-Utils
- // @description RamisAmuki Utils.
- // @author RamisAmuki
- // @grant none
- // ==/UserScript==
-
- function check_rate_price(liqs, querys) {
- const li_rate_node = liqs(querys.rate);
- const li_rate = li_rate_node != null ? parseInt(li_rate_node.innerText) : 0;
- const li_price = parseInt(liqs(querys.price).innerText.replace(",", ""));
- let base_rate = Number(localStorage.getItem("rate-input") || 90);
- let base_price = Number(localStorage.getItem("price-input") || 100);
- const result_array = [li_rate < base_rate, li_price > base_price];
- if (checkboxEnable("toggle-and-or")) {
- return result_array.some((b) => b);
- }
- return result_array.every((b) => b); // 現状はNAND検索 = OR検索
- }
-
- function disabling(li) {
- li.style.display = "none";
- }
-
- function enabling(li) {
- li.style.display = "";
- }
-
- function all_enable(querys) {
- document.querySelectorAll(querys.lists).forEach((li) => enabling(li));
- }
-
- function filter(checker, querys) {
- document.querySelectorAll(querys.lists).forEach((li) => {
- checker((q) => li.querySelector(q)) ? disabling(li) : enabling(li);
- });
- }
-
- function appendButton(
- onclick,
- querys,
- innerHTML = "Filter",
- margin = null,
- float = "right",
- height = "30px",
- color = "#000",
- backgroundColor = "#f6dbae"
- ) {
- // ボタン要素を作成
- const btn = document.createElement("button");
- const label = document.createElement("label");
-
- // ボタンを装飾
- btn.innerHTML = innerHTML;
- btn.id = innerHTML + "-btn";
- btn.style.float = float;
- btn.style.height = height;
- btn.style.color = color;
- btn.style.backgroundColor = backgroundColor;
- if (margin != null) btn.style.margin = margin;
-
- // 実行する関数
- btn.onclick = onclick;
-
- // ボタンを追加
- document.querySelector(querys.button_parent).appendChild(label);
- label.appendChild(btn);
- }
-
- function appendFilterButton(
- checker,
- querys,
- margin = null,
- innerHTML = "Filter",
- float = "right",
- height = "30px",
- color = "#000",
- backgroundColor = "#f6dbae"
- ) {
- appendButton(
- () => filter(checker, querys),
- querys,
- innerHTML,
- margin,
- float,
- height,
- color,
- backgroundColor
- );
- }
-
- function appendRatePriceInput(querys) {
- appendInput(querys, "rate", 99, 0, 90);
- appendInput(querys, "price", null, 1, 100, "100px");
- appendToggleAndOrButton(querys, "false");
- }
-
- function appendInput(querys, text, max, min, default_val, width = "55px") {
- const input = document.createElement("input");
- const label = document.createElement("label");
-
- input.type = "number";
- input.id = text + "-input";
- if (max != null) input.max = max;
- input.min = min;
- input.step = 1;
- input.style.width = width;
- input.value = localStorage.getItem(input.id) || default_val; // nullだった場合、初期値にする
- input.onchange = () => {
- localStorage.setItem(input.id, input.value);
- document.querySelector("#Filter-btn").click();
- };
- label.htmlFor = input.id;
- label.style.fontSize = "13px";
- label.style.maxWidth = "150px";
- label.style.marginLeft = label.style.marginRight = "5px";
- label.innerText = text + " : ";
-
- document.querySelector(querys.button_parent).appendChild(label);
- label.appendChild(input);
- }
-
- function appendToggleButton(querys, text, default_val) {
- const input = document.createElement("input");
- const label = document.createElement("label");
-
- input.type = "checkbox";
- input.id = text + "-checkbox";
- input.checked = JSON.parse(localStorage.getItem(input.id) || default_val);
- input.onchange = () => {
- localStorage.setItem(input.id, input.checked);
- document.querySelector("#Filter-btn").click();
- };
- label.htmlFor = input.id;
- label.style.fontSize = "13px";
- label.style.maxWidth = "150px";
- label.style.marginLeft = label.style.marginRight = "5px";
- label.innerText = text + " : ";
-
- document.querySelector(querys.button_parent).appendChild(label);
- label.appendChild(input);
- }
-
- function appendToggleAndOrButton(querys, default_val) {
- const container = document.createElement("div");
- container.className = "switch-container";
- const label = document.createElement("label");
- label.className = "switch";
- const input = document.createElement("input");
- input.type = "checkbox";
- input.id = "toggle-and-or-checkbox";
- input.className = "switch-input";
- const span = document.createElement("span");
- span.className = "switch-label";
- span.innerHTML =
- '<span class="switch-text switch-and">AND</span><span class="switch-text switch-or">OR</span>';
- input.checked = JSON.parse(localStorage.getItem(input.id) || default_val);
- input.onchange = () => {
- localStorage.setItem(input.id, input.checked);
- document.querySelector("#Filter-btn").click();
- };
- label.htmlFor = input.id;
- document.querySelector(querys.button_parent).appendChild(label);
- label.appendChild(input);
- label.appendChild(span);
- const css = `
- // .switch-container {
- // display: flex;
- // align-items: center;
- // }
-
- .switch {
- display: inline-block;
- // width: fit-content;
- // position: relative;
- }
-
- .switch-input {
- display: none;
- }
-
- .switch-label {
- display: flex;
- // align-items: center;
- // justify-content: space-between;
- }
-
- .switch-text {
- // width: fit-content;
- padding: 0 4px;
- // text-align: center;
- // font-size: 13px;
- }
-
- .switch-input:checked + .switch-label .switch-and, .switch-input:not(:checked) + .switch-label .switch-or {
- background-color: #2196F3;
- color: white;
- }
-
- .switch-input:checked + .switch-label .switch-or, .switch-input:not(:checked) + .switch-label .switch-and {
- background-color: #ccc;
- }
- `;
- const style = document.createElement("style");
- style.appendChild(document.createTextNode(css));
- document.head.appendChild(style);
- }
-
- function checkboxEnable(text) {
- return JSON.parse(localStorage.getItem(text + "-checkbox"));
- }
-
- function waitForElement(selector, callback, intervalMs, timeoutMs) {
- const startTimeInMs = Date.now();
- findLoop();
-
- function findLoop() {
- if (document.querySelector(selector) != null) {
- callback();
- return;
- } else {
- setTimeout(() => {
- if (timeoutMs && Date.now() - startTimeInMs > timeoutMs) return;
- findLoop();
- }, intervalMs);
- }
- }
- }