Sleazy Fork is available in English.

Add button on exhentai searchbox

Add your favorite keyword/tag on the searchbox

ของเมื่อวันที่ 05-11-2022 ดู เวอร์ชันล่าสุด

// ==UserScript==
// @name         Add button on exhentai searchbox
// @description  Add your favorite keyword/tag on the searchbox
// @license      MIT
// @version      0.5
// @match        https://exhentai.org/*
// @run-at       document-start
// @namespace https://greasyfork.org/users/383371
// ==/UserScript==

function add_btn(tag, name){
    let ep1 = document.createElement('input');
    ep1.type = 'button';
    ep1.value = name;
    ep1.onclick = function(){
        if(document.getElementById('searchbox').firstChild.childNodes[2].childNodes[0].value.indexOf(tag) == -1){
            document.getElementById('searchbox').firstChild.childNodes[2].childNodes[0].value = (document.getElementById('searchbox').firstChild.childNodes[2].childNodes[0].value+ ' ' + tag).trim();
            document.getElementById('searchbox').firstChild.childNodes[2].childNodes[1].click();
        }else{
            document.getElementById('searchbox').firstChild.childNodes[2].childNodes[0].value = document.getElementById('searchbox').firstChild.childNodes[2].childNodes[0].value.replace(tag, '').trim();
        }
    }
    ep1.oncontextmenu = function(e){
        e.preventDefault();
        let name = e.target.value
        let result = confirm('Delete [' + name + ']?');
        if(result){
            let config = JSON.parse(window.localStorage.getItem('config')); // GM_getValue('config');
            let new_config = [];
            for(e of config){
                if(e[1] != name){
                    new_config.push(e);
                }
            }
            window.localStorage.setItem('config', JSON.stringify(new_config)); //GM_setValue('config', new_config);
            window.location.href = window.location.href;
        }
    }
    document.getElementById('searchbox').firstChild.childNodes[2].append(ep1);
}

function add_tag(tag, name){
    let config = JSON.parse(window.localStorage.getItem('config')); // GM_getValue('config');
    if(!config){
        config = [];
    }
    config.push([tag, name]);
    window.localStorage.setItem('config', JSON.stringify(config)); //GM_setValue('config', config);
}

function add_add_tag_btn(){
    let ep1 = document.createElement('input');
    ep1.type = 'button';
    ep1.value = '+';
    ep1.onclick = function(){
        var tag_name = prompt('tag#name or tag. [language:chinese$#Chinese] or [language:chinese$]', '');
        if(!tag_name){
            return;
        }
        if(tag_name.includes('#')){
            let tmp = tag_name.split('#');
            let tag = tmp[0];
            let name = tmp[1];
            add_tag(tag, name);
            window.location.href = window.location.href;
            return;
        }else{
            var tag = tag_name;
        }
        var name = prompt('name', '');
        if(!name){
            return;
        }
        add_tag(tag, name);
        window.location.href = window.location.href;
    }
    document.getElementById('searchbox').firstChild.childNodes[2].append(ep1);
}

window.addEventListener('DOMContentLoaded',function(event) {
    if(document.getElementById('searchbox')){
        add_add_tag_btn();
        let config = JSON.parse(window.localStorage.getItem('config')); // GM_getValue('config');
        if(config){
            for(let e of config){
                add_btn(e[0], e[1]);
            }
        }
        document.getElementById('searchbox').firstChild.childNodes[2].firstChild.style.width = '519px';
    }
});