Emp: Image Full Resolution + Stretch

Image Full Resolution + Stretch

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Emp: Image Full Resolution + Stretch
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Image Full Resolution + Stretch
// @author       bighype
// @include      /^https:\/\/www\.empornium\.(me|sx|is)\/torrents\.php\?id=\d+/
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // ==========================================
    // 1. CONFIGURE YOUR BLACKLIST HERE
    // ==========================================
    // Add filenames, domains, or folder paths you want to ignore.
    const imageBlacklist =[
        'resolution.png',
        'transdescription.png',
        'transinfo.png',
        'transscreens.png',
        'description.png',
        'info.png',
        'screens.png',
        // '/smilies/',      // Example: Ignore all images in a 'smilies' directory
        // 'icon_user.gif'   // Example: Ignore specific icon names
    ];

    const MAX_ICON_WIDTH = 60; // Images narrower than 150px will also be ignored (Set to 0 to disable)

    // Stretch images and containers inside posts
    const style = document.createElement('style');
    style.textContent = `
        /* Added :not(.no-stretch) to explicitly ignore blacklisted images */
        .body img.bbcode:not(.icon):not(.no-stretch) {
            width: 100% !important;
            height: auto !important;
            max-width: none !important;
            max-height: none !important;
        }

        /* Stretch tables and bbcode divs */
        .main_column table,
        .main_column div.bbcode {
            width: 100% !important;
            max-width: none !important;
        }
    `;
    document.head.appendChild(style);

    function applyBlacklist() {
        document.querySelectorAll('img.bbcode').forEach(img => {
            // Method A: Check against the text Blacklist
            const isBlacklisted = imageBlacklist.some(keyword => img.src.includes(keyword));

            if (isBlacklisted) {
                img.classList.add('no-stretch');
                return; // Stop checking this specific image
            }

            // Method B: Auto-detect small images based on native resolution
            if (MAX_ICON_WIDTH > 0) {
                // If the image is already loaded from cache
                if (img.complete) {
                    if (img.naturalWidth > 0 && img.naturalWidth < MAX_ICON_WIDTH) {
                        img.classList.add('no-stretch');
                    }
                } else {
                    // Wait for the image to load to check its size
                    img.addEventListener('load', function() {
                        if (this.naturalWidth < MAX_ICON_WIDTH) {
                            this.classList.add('no-stretch');
                        }
                    });
                }
            }
        });
    }

    function fixLayoutContainers() {
        document.querySelectorAll('.main_column table, .main_column div.bbcode')
            .forEach(el => {
                el.removeAttribute('width');

                if (el.style.width) {
                    el.style.width = '100%';
                }
            });
    }

    function upgradeImages() {
        document.querySelectorAll('img[src*="hamsterimg.net"]').forEach(img => {
            let src = img.src;

            let full = src
                .replace('.md.jpg', '.jpg')
                .replace('.th.jpg', '.jpg')
                .replace('.md.jpeg', '.jpeg')
                .replace('.th.jpeg', '.jpeg')
                .replace('.md.png', '.png')
                .replace('.th.png', '.png');

            if (full !== src) {
                img.src = full;
            }
        });
    }

    upgradeImages();
    applyBlacklist(); // Execute the blacklist checks
    fixLayoutContainers();
})();