Last active
May 7, 2021 10:32
-
-
Save Angeart/02965594d1207fc764a5d87cae134728 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Booth Ignore Search | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.1.6 | |
| // @description Boothの検索結果から特定のキーワードを除外します(正規表現可能) | |
| // @author Angeart | |
| // @match https://booth.pm/* | |
| // @icon https://www.google.com/s2/favicons?domain=booth.pm | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| const ignoreSearchBox = ` | |
| <div class="item-search-box"> | |
| <form class="item-search"> | |
| <input name="utf8" type="hidden" value="✓"> | |
| <span class="twitter-typeahead" style="position: relative; display: inline-block; direction: ltr;"> | |
| <input type="search" value="" autocomplete="off" class="ac-tags item-search-input tt-hint" readonly="" spellcheck="false" tabindex="-1" style="position: absolute; top: 0px; left: 0px; border-color: transparent; box-shadow: none; opacity: 1; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);"> | |
| <input type="search" name="query" id="ignore-query" value="" placeholder="ignore..." autocomplete="off" class="ac-tags item-search-input tt-input" spellcheck="false" dir="auto" style="position: relative; vertical-align: top; background-color: transparent;"> | |
| <pre aria-hidden="true" style="position: absolute; visibility: hidden; white-space: pre; font-family: Arial; font-size: 13.3333px; font-style: normal; font-variant: normal; font-weight: 400; word-spacing: 0px; letter-spacing: 0px; text-indent: 0px; text-rendering: auto; text-transform: none;"></pre> | |
| <span class="tt-dropdown-menu" style="position: absolute; top: 100%; left: 0px; z-index: 100; display: none; right: auto;"> | |
| <div class="tt-dataset-0"></div> | |
| </span> | |
| </span> | |
| <input id="exec-ignore" type="checkbox" class="btn search"> | |
| </form> | |
| </div> | |
| `; | |
| document.querySelector('.global-nav').insertAdjacentHTML('beforeend', ignoreSearchBox); | |
| const ignoreSearchBoxEl = document.querySelector('#ignore-query'); | |
| ignoreSearchBoxEl.value = sessionStorage.ignoreQuery ?? ""; | |
| const ignoreExec = document.querySelector("#exec-ignore"); | |
| ignoreExec.checked = (sessionStorage.execIgnore === 'true') ?? false; | |
| const exec = function() { | |
| const ignoreSearchBoxEl = document.querySelector('#ignore-query'); | |
| [...document.querySelectorAll('.item-card')].forEach(v => v.style.display = 'inline-block'); | |
| if (ignoreExec.checked && ignoreSearchBoxEl.value !== '') { | |
| let matchRegex = null; | |
| try { | |
| matchRegex = new RegExp(ignoreSearchBoxEl.value, "ig"); | |
| } catch { | |
| return; | |
| } | |
| const matchedEl = [...document.querySelectorAll('.item-card')].filter(v => v.querySelector('.item-card__title > a').text.match(matchRegex)) ?? []; | |
| matchedEl.forEach(v => v.style.display = 'none'); | |
| window.matchedEl = matchedEl; | |
| } else if (window.matchedEl != null) { | |
| window.matchedEl.forEach(v => v.style.display = 'inline-block'); | |
| } | |
| } | |
| ignoreSearchBoxEl.addEventListener('input', function() { | |
| sessionStorage.ignoreQuery = this.value; | |
| exec(); | |
| }); | |
| if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") { | |
| exec(); | |
| } else { | |
| document.addEventListener("DOMContentLoaded", function(event) { | |
| exec(); | |
| }); | |
| } | |
| ignoreExec.addEventListener("change", function () { | |
| exec(); | |
| sessionStorage.execIgnore = this.checked; | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment