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