里屋格式优化

调节分栏比例和图片展示大小

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         里屋格式优化
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  调节分栏比例和图片展示大小
// @author       You
// @match        https://www.253874.net/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        // 调整 frameset 宽度
        const outerFrameSet = document.getElementById('gb_bodys');
        if (outerFrameSet) {
            // 设置第一列为页面宽度的 30%,第二列占据剩余空间
            outerFrameSet.cols = "20%,*";
        }

        const posts = document.querySelectorAll('.post_list');
        posts.forEach(post => {
            const images = post.querySelectorAll('img');
            images.forEach(img => {
                // 跳过gif表情包
                if (img.src.toLowerCase().endsWith('.gif')) {
                    return;
                }

                // 设置图片的初始高度,保持宽高比
                img.style.height = '300px';
                img.style.width = 'auto';

                let originalHeight = img.naturalHeight;
                let originalWidth = img.naturalWidth;

                // 点击时切换图片大小
                img.addEventListener('click', () => {
                    if (img.style.height === '300px') {
                        img.style.height = originalHeight + 'px';
                        img.style.width = originalWidth + 'px';
                    } else {
                        img.style.height = '300px';
                        img.style.width = 'auto';
                    }
                });
            });
        });
    });
})();