E-Hentai Enhancements

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
    }

})();