Google Images Fullscreen

Надежно открывает большие картинки в Google Images на весь экран при клике.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Advertisement:

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Advertisement:

// ==UserScript==
// @name         Google Images Fullscreen
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  Надежно открывает большие картинки в Google Images на весь экран при клике.
// @author       You
// @match        *://*.google.com/*
// @match        *://*.google.ru/*
// @match        *://*.google.by/*
// @match        *://*.google.kz/*
// @match        *://*.google.com.ua/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('click', function(e) {
        // 1. Если уже в полноэкранном режиме — выходим
        if (document.fullscreenElement) {
            e.preventDefault();
            e.stopPropagation();
            document.exitFullscreen();
            return;
        }

        // Проверяем, что находимся в разделе картинок
        const urlParams = new URLSearchParams(window.location.search);
        if (urlParams.get('tbm') !== 'isch' && urlParams.get('udm') !== '2') return;

        // 2. ПРОБИВАЕМ СЛОИ: берем все элементы, которые находятся ровно под курсором
        const elementsUnderCursor = document.elementsFromPoint(e.clientX, e.clientY);
        
        let targetImg = null;
        for (let el of elementsUnderCursor) {
            // Ищем первую картинку в стопке элементов
            if (el.tagName && el.tagName.toLowerCase() === 'img') {
                targetImg = el;
                break;
            }
        }

        if (!targetImg) return;

        // 3. Проверяем, что картинка большая (игнорируем миниатюры в сетке)
        if (targetImg.clientWidth > 200 && targetImg.clientHeight > 200) {
            e.preventDefault();
            e.stopPropagation();

            // 4. Запоминаем старые стили, чтобы вернуть их после закрытия
            const originalObjectFit = targetImg.style.objectFit;
            const originalBackground = targetImg.style.background;

            // Задаем стили, чтобы в полноэкранном режиме картинка не искажалась
            targetImg.style.objectFit = 'contain';
            targetImg.style.background = 'black';

            // Слушатель для возврата стилей при выходе из фуллскрина
            const onFullscreenChange = () => {
                if (!document.fullscreenElement) {
                    targetImg.style.objectFit = originalObjectFit;
                    targetImg.style.background = originalBackground;
                    document.removeEventListener('fullscreenchange', onFullscreenChange);
                }
            };
            document.addEventListener('fullscreenchange', onFullscreenChange);

            // 5. Разворачиваем на весь экран
            if (targetImg.requestFullscreen) {
                targetImg.requestFullscreen();
            } else if (targetImg.webkitRequestFullscreen) {
                targetImg.webkitRequestFullscreen(); // Safari
            }
        }
    }, true); 
})();