Greasy Fork is available in English.

Google Images Fullscreen

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

Advertisement:

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.

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

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

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

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

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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