E-Hentai Enhancements

AI detection, direct full-picture opening, and gallery layout enhancements

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         E-Hentai Enhancements
// @namespace    B1773rm4n
// @version      2026-09-13
// @description  AI detection, direct full-picture opening, and gallery layout enhancements
// @author       B1773rm4n
// @license      WTFPL
// @copyright    WTFPL
// @source       https://github.com/B1773rm4n/Tampermonkey_Userscripts/blob/main/ehentai.js
// @match        https://exhentai.org/*
// @match        https://e-hentai.org/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=e-hentai.org
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const url = window.location.href;

    /*
     * ------------------------------------------------------------
     * Full-picture pages
     * ------------------------------------------------------------
     *
     * If opening an E-Hentai "show picture" page, redirect directly
     * to the actual image.
     */

    const fullPictureRegex = /\/s\/[0-f]{10}\/.*-\d+/;

    if (fullPictureRegex.test(url)) {
        // Redirect E-Hentai -> ExHentai first.
        if (url.includes('e-hentai.org')) {
            window.location.replace(
                url.replace('e-hentai.org', 'exhentai.org')
            );
            return;
        }

        const image = document.querySelector('#i3 img');

        if (image && image.src) {
            window.location.assign(image.src);
            return;
        }
    }


    /*
     * ------------------------------------------------------------
     * Gallery-page handling
     * ------------------------------------------------------------
     * Mark AI galleries
     */

    if (url.includes('/g/')) {
        const titleElement = document.getElementById('gn');
        const aiTagElement = document.getElementById('ta_other:ai_generated');

        const title = titleElement
            ? titleElement.innerText.toLowerCase()
            : '';

        const aiTag = aiTagElement
            ? aiTagElement.innerText.toLowerCase()
            : '';

        if (
            title.includes('ai generated') ||
            title.includes('ai-generated') ||
            aiTag.includes('ai generated') ||
            aiTag.includes('ai-generated')
        ) {
            document.body.style.color = '#F00';
            document.body.style.backgroundColor = '#400';

            const gdt = document.getElementById('gdt');

            if (gdt) {
                gdt.style.backgroundColor = '#400';
            }
        }
    }


    /*
     * ------------------------------------------------------------
     * Gallery-list handling
     * ------------------------------------------------------------
     * Mark AI galleries
     */

    if (
        url.includes('advsearch') ||
        url.includes('/tag') ||
        url.includes('popular')
    ) {
        const galleryList = document.querySelectorAll('.glname');

        galleryList.forEach(function (galleryItem) {
            const text = galleryItem.innerText.toLowerCase();

            if (
                text.includes('ai generated') ||
                text.includes('ai-generated')
            ) {
                const galleryContainer =
                    galleryItem.parentElement?.parentElement;

                if (galleryContainer) {
                    galleryContainer.style.backgroundColor = '#400';
                }
            }
        });
    }


    /*
     * ------------------------------------------------------------
     * Gallery layout
     * ------------------------------------------------------------
     */

    function configureGalleryLayout() {
        // Every .gt200 gets zero gap.
        document.querySelectorAll('.gt200').forEach(function (element) {
            element.style.gap = '0';
        });

        const gdt = document.getElementById('gdt');

        if (!gdt) {
            return;
        }

        // Force exactly three images/items per row.
        gdt.style.display = 'grid';
        gdt.style.gridTemplateColumns = 'repeat(3, 1fr)';

        // Remove the site's minimum width restriction.
        gdt.style.minWidth = '0';
        gdt.style.minInlineSize = '0';

        // Remove padding.
        gdt.style.padding = '0';

        // Jump to the beginning of the gallery.
        gdt.scrollIntoView({
            behavior: 'instant',
            block: 'start'
        });
    }


    /*
     * ------------------------------------------------------------
     * Run after the page has loaded.
     * ------------------------------------------------------------
     */

    if (document.readyState === 'loading') {
        document.addEventListener(
            'DOMContentLoaded',
            configureGalleryLayout,
            { once: true }
        );
    } else {
        configureGalleryLayout();
    }

})();