Google Images Fullscreen

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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