E-Hentai Enhancements

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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();
    }

})();