Sleazy Fork is available in English.

LOLICON Wide Hentai

Full Width E-Hentai and Exhentai, dynamically adjusting the display width, It also allows you to adjust the size and margins of the thumbnails

// ==UserScript==
// @name                LOLICON Wide Hentai
// @name:zh-CN          LOLICON 全宽度E绅士
// @namespace           https://greasyfork.org/scripts/516145
// @version             2024.11.26
// @description         Full Width E-Hentai and Exhentai, dynamically adjusting the display width, It also allows you to adjust the size and margins of the thumbnails
// @description:zh-cn   全宽度E绅士,动态调整显示宽度,还可以调整缩略图的大小和边距
// @icon                https://e-hentai.org/favicon.ico
// @match               https://e-hentai.org/*
// @match               https://exhentai.org/*
// @exclude             https://e-hentai.org/s/*
// @exclude             https://exhentai.org/s/*
// @run-at              document-end
// @grant               GM_setValue
// @grant               GM_getValue
// @grant               GM_registerMenuCommand
// @noframes
// ==/UserScript==

(function() {
    'use strict';

    function $(id) { return document.getElementById(id); }

    function c(id) { return document.getElementsByClassName(id); }

    // 获取当前设备的设备像素比(DPR)
    const devicePixelRatio = window.devicePixelRatio || 1;

    // 获取用户语言
    const userLang = navigator.language || navigator.userLanguage;

    // 定义语言包
    const translations = {
        "zoomFactor": {
            "en": "Zoom Factor for thumbnail",
            "zh": "缩略图缩放比例"
        },
        "zoomPrompt": {
            "en": "Enter new zoom factor for thumbnail 0.5 ~ 10 : \nDefault 1",
            "zh": "请输入新的缩略图缩放比例 0.5 ~ 10 : \n默认 1"
        },
        "zoomAlert": {
            "en": "Refresh the page to apply changes \nZoom factor updated to: ",
            "zh": "刷新网页生效 \n缩放比例已更新为: "
        },
        "zoomInvalid": {
            "en": "Please enter a valid number!",
            "zh": "请输入有效的数字!"
        },
        "zoomRange": {
            "en": "Zoom factor must be between 0.5 and 10!",
            "zh": "缩放比例必须在 0.5 到 10 之间!"
        },
        "margin": {
            "en": "Minimum Margin for thumbnail",
            "zh": "缩略图最小边距"
        },
        "marginPrompt": {
            "en": "Enter new minimum margins for thumbnails (0-100)px: \nDefault 10",
            "zh": "请输入新的缩略图最小边距(0~100)px: \n默认 10"
        },
        "marginAlert": {
            "en": "Refresh the page to apply changes \nMinimum Margin updated to: ",
            "zh": "刷新网页生效 \n最小边距已更新为: "
        },
        "marginInvalid": {
            "en": "Please enter a valid number!",
            "zh": "请输入有效的数字!"
        },
        "marginRange": {
            "en": "Minimum Margin must be between 0 and 100!",
            "zh": "最小边距必须在 0 到 100 之间!"
        }
    };

    // 根据用户语言选择对应的文本
    const translate = (key) => translations[key][userLang.startsWith('zh') ? 'zh' : 'en'];

    // 注册自定义菜单  缩放比例
    let zoomFactor = GM_getValue("zoomFactor", 1);
    GM_registerMenuCommand(`${translate("zoomFactor")}: ${zoomFactor} x`, function() {
        const userInput = prompt(translate("zoomPrompt"), zoomFactor);
        if (userInput !== null) {
            const inputValue = parseFloat(userInput.trim());
            if (isNaN(inputValue)) {
                alert(translate("zoomInvalid"));
            } else if (inputValue < 0.5 || inputValue > 10) {
                alert(translate("zoomRange"));
            } else {
                GM_setValue("zoomFactor", inputValue);
                const isSure = confirm(`${translate("zoomAlert")} ${inputValue}`);
                if (isSure) {
                    location.reload();
                } else {
                    zoomFactor = GM_getValue("zoomFactor");
                }
            }
        }
    });
    // 注册自定义菜单  最小边距
    let margin = GM_getValue("margin", 10);
    GM_registerMenuCommand(`${translate("margin")}: ${margin} px`, function() {
        const userInput = prompt(translate("marginPrompt"), margin);
        if (userInput !== null) {
            const inputValue = parseFloat(userInput.trim());
            if (isNaN(inputValue)) {
                alert(translate("marginInvalid"));
            } else if (inputValue < 0 || inputValue > 100) {
                alert(translate("marginRange"));
            } else {
                GM_setValue("margin", inputValue);
                const isSure = confirm(`${translate("marginAlert")} ${inputValue} px`);
                if (isSure) {
                    location.reload();
                } else {
                    margin = GM_getValue("margin");
                }
            }
        }
    });

    // 保存初始表格行状态
    let initialTableRows = null;

    const columnWidthS = 250 * zoomFactor + margin * 2; // 每列的宽度 250-400 270
    const columnWidthSb = columnWidthS + (2 / devicePixelRatio); // 加上缩略图边框,边框宽度受设备像素比影响
    const columnWidthG = 240; // 画廊每列的宽度
    const marginAdjustmentS = 15; // 外边距调整值
    const marginAdjustmentG = 30; // 画廊外边距调整值

    // 根据页面宽度动态调整列数
    function adjustColumns() {
        const width = window.innerWidth;
        if (window.location.pathname.indexOf('/g/') != 0 && c('itg gld')[0]) { // 非画廊页面 且 缩略图模式
            let columnsS = Math.floor(Math.max((width - marginAdjustmentS) / columnWidthSb, c('ido')[0].clientWidth / columnWidthSb, 1)); // 计算列数
            const clientWidthS = columnsS * columnWidthSb; // 计算宽度
            c('ido')[0].style.maxWidth = clientWidthS + 'px'; // 设置最大宽度   1370
            c('itg gld')[0].style = `grid-template-columns: repeat(${columnsS}, 1fr); Width:100%`; // 设置列数和边距
            const searchbox = $('searchbox'); //搜索盒子
            if (searchbox) {
                const tbody = searchbox.querySelector('tbody');
                if (tbody) {
                    // 保存初始表格状态
                    if (!initialTableRows) {
                        initialTableRows = tbody.innerHTML;
                    }
                    if (clientWidthS >= 1460) {
                        // 合并表格行
                        const rows = tbody.querySelectorAll('tr');
                        if (rows.length >= 2) {
                            const firstRow = rows[0];
                            const secondRow = rows[1];
                            Array.from(secondRow.children).forEach(td => {
                                firstRow.appendChild(td);
                            });
                            secondRow.remove();
                        }
                    } else {
                        // 恢复为初始状态
                        tbody.innerHTML = initialTableRows;
                    }
                }
                // 调整搜索盒子大小
                if (clientWidthS >= 1460) {
                    if (c('idi')[0]) { c('idi')[0].style.width = 720 + 670 + 'px'; }
                    if (c('idi')[1]) { c('idi')[1].style.width = 720 + 670 + 'px'; }
                    if ($('f_search')) { $('f_search').style.width = 560 + 670 + 'px'; }
                } else {
                    if (c('idi')[0]) { c('idi')[0].style.width = 720 + 'px'; }
                    if (c('idi')[1]) { c('idi')[1].style.width = 720 + 'px'; }
                    if ($('f_search')) { $('f_search').style.width = 560 + 'px'; }
                }
            }
        } else if (window.location.pathname.indexOf('/g/') == 0) { // /g/ 画廊页面
            let columnsG = Math.floor((width - marginAdjustmentG) / columnWidthG); // 减去边距,并计算列数
            columnsG = Math.max(columnsG, 3);
            const clientWidthG = 700 + (columnsG - 3) * columnWidthG;
            if (columnsG >= 6) {
                if (c('gm')[0]) { c('gm')[0].style.maxWidth = (clientWidthG + 20) + 'px'; } // 设置最详情大宽度 720 960 1200
                if (c('gm')[1]) { c('gm')[1].style.maxWidth = (clientWidthG + 20) + 'px'; } // 设置最评论区大宽度 720 960 1200
                if ($('gd2')) { $('gd2').style.width = (clientWidthG - 255) + 'px'; } // 设置标题栏宽度 710 925
                if ($('gmid')) { $('gmid').style.width = (clientWidthG - 250) + 'px'; } // 设置标签栏宽度 710 930
                if ($('gd4')) { $('gd4').style.width = (clientWidthG - 600) + 'px'; } // 设置标签栏宽度 360 580
                if ($('gdo')) { $('gdo').style.maxWidth = (clientWidthG + 20) + 'px'; } // 设置缩略图设置栏最大宽度 720 960 1200
            } else {
                if (c('gm')[0]) { c('gm')[0].style.maxWidth = ''; } // 设置最详情大宽度
                if (c('gm')[1]) { c('gm')[1].style.maxWidth = ''; } // 设置最评论区大宽度
                if ($('gd2')) { $('gd2').style.width = ''; } // 设置标题栏宽度
                if ($('gmid')) { $('gmid').style.width = ''; } // 设置标签栏宽度
                if ($('gd4')) { $('gd4').style.width = '' } // 设置标签栏宽度
                if ($('gdo')) { $('gdo').style.maxWidth = ''; } // 设置缩略图设置栏最大宽度
            }
            const gdt = $('gdt');
            if (gdt) {
                gdt.style.maxWidth = clientWidthG + 'px'; // 设置最大宽度 700 940 1180
                if (gdt.classList.contains("gt100")) {
                    gdt.style.gridTemplateColumns = `repeat(` + columnsG * 2 + `, 1fr)`;
                } else if (gdt.classList.contains("gt200")) {
                    gdt.style.gridTemplateColumns = `repeat(` + columnsG + `, 1fr)`;
                }
            }
        }
    }
    // 根据设置调整缩略图大小
    function zoomThumbnail() {
        if (window.location.pathname.indexOf('/g/') != 0 && c('itg gld')[0]) {
            const gl1t = document.querySelectorAll('.gl1t');
            const minWidthNumber = parseFloat(getComputedStyle(c('ido')[0]).minWidth);
            const columnWidthSbm = Math.max(columnWidthSb, minWidthNumber / Math.floor(Math.max(minWidthNumber / columnWidthSb, 1)));
            // 处理每个 gl1t 元素
            gl1t.forEach(gl1t => {
                gl1t.style.minWidth = columnWidthS + 'px';
                gl1t.style.maxWidth = columnWidthSbm + 'px';
                const gl3t = gl1t.querySelector('.gl3t');
                if (zoomFactor != 1 && gl3t) {
                    const originalWidth = gl3t.clientWidth;
                    const originalHeight = gl3t.clientHeight;
                    const newWidth = originalWidth * zoomFactor;
                    const newHeight = originalHeight * zoomFactor;
                    gl3t.style.width = newWidth + 'px';
                    gl3t.style.height = newHeight + 'px';
                    const img = gl3t.querySelector('img');
                    if (img) {
                        const originalImgWidth = img.clientWidth;
                        const originalImgHeight = img.clientHeight;
                        const newImgWidth = originalImgWidth * zoomFactor;
                        const newImgHeight = originalImgHeight * zoomFactor;
                        img.style.width = newImgWidth + 'px';
                        img.style.height = newImgHeight + 'px';
                        img.style.top = (newHeight - newImgHeight) / 2 + 'px';
                    }
                }
                // 当列宽小于200时,处理换行逻辑
                if (columnWidthS < 200) {
                    const gl5t = gl1t.querySelector('.gl5t');
                    if (gl5t) {
                        gl5t.style.flexWrap = 'wrap';
                        gl5t.style.height = '92px';
                        gl5t.querySelector('div:nth-child(1)').style.paddingRight = '1px';
                    }
                }
            });
        }
    }

    // 初始化和窗口大小变化时调整列数
    adjustColumns();
    zoomThumbnail();
    window.addEventListener('resize', adjustColumns);

})();