Clone search page navigation on top for mobile and options for faster tag filtering in top bar
Pada tanggal
// ==UserScript==
// @name nh Navigation Improvements
// @description Clone search page navigation on top for mobile and options for faster tag filtering in top bar
// @namespace xspeed.net
// @license MIT
// @version 1
// @icon https://nhentai.net/favicon.ico
// @match *://nhentai.net/*
// @grant none
// ==/UserScript==
"use strict";
async function showTextPrompt(msg) {
const text = document.createElement("p");
text.innerText = msg;
const input = document.createElement("input");
input.type = "search";
const link = document.createElement("i");
link.className = "fa fa-paste";
const button = document.createElement("button");
button.className = "btn btn-primary btn-square";
button.type = "submit";
button.appendChild(link);
const form = document.createElement("form");
form.className = "search";
form.role = "search";
form.method = "dialog";
form.appendChild(input);
form.appendChild(button);
const dialog = document.createElement("dialog");
dialog.appendChild(text);
dialog.appendChild(form);
const style = getComputedStyle(document.body);
dialog.style.backgroundColor = style.getPropertyValue("background-color");
dialog.style.color = style.getPropertyValue("color");
document.body.appendChild(dialog);
dialog.showModal();
return new Promise((resolve, reject) => form.addEventListener('submit', () => {
resolve(input.value);
dialog.remove();
}, { once: true }));
}
async function onBlockClick(event, tags) {
event.stopImmediatePropagation();
event.preventDefault();
const input = document.querySelector("input[type=search]");
const str = tags ?? await showTextPrompt("Specify tags, separate by commas");
if (str) {
str.split(',').map(x => x.trim()).filter(x => x).forEach(x => input.value += " -tag:" + x);
const btn = document.querySelector("button[type=submit]");
btn.click();
}
}
function setupBtn(elem) {
var item = elem.firstChild.cloneNode(true);
var link = item.firstChild;
link.href = "#";
link.innerText = "Block default";
link.addEventListener("click", e => onBlockClick(e, "bbm,netorare,vore,scat,guro"));
elem.insertBefore(item, elem.firstChild);
item = elem.firstChild.cloneNode(true);
link = item.firstChild;
link.href = "#";
link.innerText = "Block tags";
link.addEventListener("click", onBlockClick);
elem.insertBefore(item, elem.firstChild);
}
const content = document.getElementById("content");
const pagination = document.querySelector("section.pagination");
const input = document.querySelector("input[type=search]");
if (content && pagination) {
const clone = pagination.cloneNode(true);
const spacer = clone.querySelector(".ios-mobile-webkit-bottom-spacing");
if (spacer) spacer.remove();
content.insertBefore(clone, content.firstChild);
}
if (!input.value) {
input.value = "English ";
}
setupBtn(document.querySelector("ul.menu"));
setupBtn(document.querySelector("ul.dropdown-menu"));