E-Hentai Enhancements

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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

})();