Google Images Fullscreen

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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!)

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.

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

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