NHentai only english

Make all search through NHentai use english language

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         NHentai only english
// @namespace    Dar9586
// @version      1.0
// @description  Make all search through NHentai use english language
// @author       Dar9586
// @license      https://opensource.org/licenses/MIT
// @match        *://nhentai.net/*
// @grant        none
// ==/UserScript==

'use strict';
function hideEnglishTag(){
    let textBox=document.getElementsByName('q')[0];
    if(textBox.value.includes("language:english"))textBox.value=textBox.value.replace("language:english","").trim();
}
function englishMode(){
    let textBox=document.getElementsByName('q')[0];
    if(!textBox.value.includes("english"))textBox.value+=' language:english';
}
function redirectToEnglish(list){
    for (let item of list) {
        //                                 domain           type  name
        item.href=item.href.replace(/https:\/\/nhentai.net\/(.*)\/(.*)\//,'https://nhentai.net/search/?q=$1:"$2"+language:english');
    }
}
//remove english tag because it's ugly
hideEnglishTag();
//redirect if going to main page
if(window.location.pathname=="/")window.location.replace("https://nhentai.net/search/?q=language%3Aenglish");
//append english to end of query
document.getElementsByTagName('form')[0].onsubmit=englishMode;
//replace logo location
document.getElementsByTagName('nav')[0].childNodes[0].href='/search/?q=language%3Aenglish'
//when using tab in navbar
if(document.getElementById("tag-container")!=null)redirectToEnglish(document.getElementById("tag-container").getElementsByTagName("a"));
//on galleries
if(document.getElementById("tags")!=null)redirectToEnglish(document.getElementById("tags").getElementsByTagName("a"));