E-Hentai Enhancements

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

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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

})();