☰

NHentai custom search

A fork of Dar9586's Nhentai Only english to include a changeable custom search.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu betiği yüklemek için bir betik yöneticisi eklentisi yüklemeniz gerekecektir.

(Zaten bir betik yöneticim var, hadi yükleyelim!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         NHentai custom search
// @namespace    mr feelgood
// @version      1.3.2
// @description  A fork of Dar9586's Nhentai Only english to include a changeable custom search.
// @author       h8code
// @license      https://opensource.org/licenses/MIT
// @match        *://nhentai.net/*
// @run-at       document-end
// @grant        none
// @license      https://opensource.org/licenses/MIT
// ==/UserScript==

'use strict';

console.log("Tampermonkey script loaded");

const search = [
    {
        val: 'language:english',
        simplified: 'english'
    },
    {
       val: '-tag:"ai generated"',
       simplified: 'ai generated'
    },
    // EXTRA SEARCH TERMS
    // {
    //    val: "tag:some_tag",
    //    simplified: "some_tag",
    // },
];

function getSearchString() {
    let s = '';
    for (let v of search) {
        s += ' ';
        s += v.val;
    }
    return s.trim();
}

function hideSearch(){
    let textBox=document.getElementsByName('q')[0];
    for (let v of search) {
        console.log({textboxValue: textBox.value});
        if(textBox.value.includes(v.val))textBox.value=textBox.value.replace(v.val,"").trim();
    }
}

function setSearch(){
    let textBox=document.getElementsByName('q')[0];
    for (let v of search) {
        if(!textBox.value.includes(v.simplified))textBox.value+=` ${v.val}`;
    }
}

function redirectToSearch(list){
    let searchStr = encodeURIComponent(getSearchString());
    for (let item of list) {
        let old = item.href
        //                                 domain           type  name
        item.href=item.href.replace(/https:\/\/nhentai.net\/(.*)\/(.*)\//,'https://nhentai.net/search/?q=$1:"$2" '+searchStr);
        let newI = item.href;
        console.log({old, new: newI});
    }
}




(function() {
    'use strict';

    function runScript() {
        console.log("Running script on:", location.href);

            //remove english tag because it's ugly
            hideSearch();
            //redirect if going to main page
            if(window.location.pathname=="/")window.location.replace("https://nhentai.net/search/?q="+encodeURIComponent(getSearchString()))
            //append english to end of query
            document.getElementsByTagName('form')[0].onsubmit=setSearch
            //replace logo location
            document.getElementsByTagName('nav')[0].childNodes[0].href='/search/?q='+encodeURIComponent(getSearchString())
            //when using tab in navbar
            if(document.getElementById("tag-container")!=null)redirectToSearch(document.getElementById("tag-container").getElementsByTagName("a"))
            //on galleries
            if(document.getElementById("tags")!=null)redirectToSearch(document.getElementById("tags").getElementsByTagName("a"))

    }

    // Run once on load
    runScript();

    // Detect changes
    new MutationObserver(() => {
        console.log("Observed");
        console.log(location.href);

        runScript();
    }).observe(document, { subtree: true, childList: true});
})();