fix Google image popup

show images in popup instead of opening the source

目前為 2020-07-27 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         fix Google image popup
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  show images in popup instead of opening the source
// @author       You
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @match        https://www.google.com/*
// @grant        none
// ==/UserScript==

function GM_addStyle(css) {
    const style = document.getElementById("GM_addStyle") || (function() {
        const style = document.createElement('style');
        style.type = 'text/css';
        style.id = "GM_addStyle";
        document.head.appendChild(style);
        return style;
    })();
    const sheet = style.sheet;
    sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length);
}
GM_addStyle('.fixmodal {position:fixed;background-color:rgba(0, 0, 0, 0.5);height:100%;width:100%;top:0;left:0;display:none; z-index: 1000;}');
GM_addStyle('#fixPopup {padding:5px;text-align:center;}');
GM_addStyle('.fixmodalWrap {border:1px solid #000;background:#fff; margin:5% auto; position:relative;width: fit-content;} ');

(function() {
    'use strict';
    var test = window.screen.height - 400;
GM_addStyle('#fixPopup img {max-height:'+test+'px;max-width:100%}');
    var callbackRoot = function(mutationsList, observer) {
        for(var mutation of mutationsList) {
            mutation.addedNodes.forEach(function(node) {
                if ($(node).find(".v4dQwb")){
                    var imageNode = $(node).find(".v4dQwb");
                    if (imageNode.hasClass("fixAttached") == false){
                        imageNode.addClass("fixAttached");
                        imageNode.click(function(e){
                            var thisImgSrc = $(this).find("img").attr("src");
                            e.stopPropagation();
                            $(".fixmodal").fadeIn("fast");
                            $("#fixPopup img").remove();
                            $('<img src="'+thisImgSrc+'" alt="image3" />').appendTo("#fixPopup");
                            e.preventDefault();
                        });
                    }
                }
            });
        }
    };
    function attachObserver(){
        var obs = $('.T1diZc');
        var isReady = obs.length > 0;
        if (!isReady) {
            setTimeout(obs, 300);
            return;
        }
        $("body").append('<div class="fixmodal"> <div class="fixmodalWrap"><div id="fixPopup"></div> </div></div>');
        $(document).on("click", function () {
            $(".fixmodal").fadeOut("fast");
        });
        $(".modalWrap").on("click", function (e) {
            e.stopPropagation();
        });
        console.log("attaching");
        var config = { attributes: false, childList: true, subtree: true };
        var targetNodeRoot = $(obs).first().get(0);
        var observerroot = new MutationObserver(callbackRoot);
        observerroot.observe(targetNodeRoot, config);
    }
    attachObserver();
})();