Qwant Image Size Highlighter

Highlights images with different borders depending on their size (>3Mpx: green, >2Mpx: yellow, >1Mpx: orange, <=1Mpx: red)

目前為 2025-04-06 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Qwant Image Size Highlighter
// @name:it Evidenzia la dimensione delle immagini su Qwant
// @namespace StephenP
// @version 1.0.1
// @description Highlights images with different borders depending on their size (>3Mpx: green, >2Mpx: yellow, >1Mpx: orange, <=1Mpx: red)
// @description:it Evidenzia le immagini usando bordi differenti a seconda della loro dimensione (>3Mpx: verde, >2Mpx: giallo, >1Mpx: arancio, <=1Mpx: rosso)
// @author      StephenP
// @match https://www.qwant.com/*
// @license AGPL-3.0-or-later
// @run-at document-idle
// ==/UserScript==

(() => {
    const XXL = 3000000; // Minimum width * height to highlight
    const XL = 2000000; // Minimum width * height to highlight
    const L = 1000000; // Minimum width * height to highlight
    var pageURL="";

    function checkReload(){
        if(document.location.href!=pageURL){
          if((document.location.href.includes("t=images"))&&(!pageURL.includes("t=images"))){
            checkImageSizes(document.body);
            // Create mutation observer
            const observer = new MutationObserver(observerCallback);

            // Start observing the document for changes in images
            observer.observe(document.body, {
                childList: true,
                subtree: true
            });
          }
          pageURL=document.location.href;
        }
    }

    function checkImageSizes() {
        const images = document.querySelectorAll('[data-testid="imageResult"]');

        images.forEach(image => {
            const sizeContainer = image.querySelector('._3kuJS._21z97._2huh0');

            if (sizeContainer) {
                const dimensions = sizeContainer.textContent.split('×');
                const width = parseInt(dimensions[0]);
                const height = parseInt(dimensions[1]);

                if (width * height > XXL) {
                    image.style.borderColor = 'green';
                    image.style.borderWidth = '5px';
                    image.style.borderStyle = 'solid';
                    image.style.borderRadius = 'var(--border-radius-150)';
                }
                else if (width * height > XL) {
                    image.style.borderColor = 'yellow';
                    image.style.borderWidth = '4px';
                    image.style.borderStyle = 'solid';
                    image.style.borderRadius = 'var(--border-radius-150)';
                }
                else if (width * height > L) {
                    image.style.borderColor = 'orange';
                    image.style.borderWidth = '3px';
                    image.style.borderStyle = 'solid';
                    image.style.borderRadius = 'var(--border-radius-150)';
                }
                else{
                    image.style.borderColor = 'red';
                    image.style.borderWidth = '2px';
                    image.style.borderStyle = 'solid';
                    image.style.borderRadius = 'var(--border-radius-150)';
                }
            }
        });
    }

    function observerCallback(mutations) {
        mutations.forEach(mutation => {
            if (mutation.addedNodes.length > 0) {
                checkImageSizes(mutation.addedNodes);
            }
        });
    }



    // Check initial image sizes
    checkReload();
    setInterval(checkReload,1000);

})();