Emp: Image Full Resolution + Stretch

Image Full Resolution + Stretch

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل 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();
})();