gImage

This script brings back the Image button from the Google Image Search, and it does it better than anyone else!

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         gImage
// @namespace    gimage
// @version      2.4.1
// @description  This script brings back the Image button from the Google Image Search, and it does it better than anyone else!
// @author       pipe01
// @match        *://www.google.com/*tbm=isch*
// @match        *://www.google.es/*tbm=isch*
// @grant        none
// @license MIT
// @copyright 2018, pipe01 (https://github.com/pipe01)
// ==/UserScript==

(function() {
    'use strict';

    const VisitButtonSelector = ".irc_vpl";
    const ImageSelector = ".irc_mi";

    //Thanks to https://github.com/danklammer
    const IconSVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="10" height="10" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-width="2"><path d="M20 24 L12 16 2 26 2 2 30 2 30 24 M16 20 L22 14 30 22 30 30 2 30 2 24" /><circle cx="10" cy="9" r="3" /></svg>';

    function getParent(node, level)
    {
        var ret = node;
        while (level-- > 0)
        {
            ret = ret.parentNode;

            if (ret == null) return node;
        }
        return ret;
    }

    //Wait for the page to fully load
    var interval = setInterval(() =>
    {
        if (document.querySelectorAll(VisitButtonSelector).length > 0)
        {
            clearInterval(interval);
            main();
        }
    }, 100);

    function main()
    {
        var l = document.querySelectorAll(VisitButtonSelector);
        for (var i in l)
        {
            var btn = l[i].parentNode.cloneNode(true);
            var parent = l[i].parentNode.parentNode;
            parent.insertBefore(btn, parent.children[0]);
 
            if (l[i].children == null) continue;

            l[i].children[0].innerHTML = IconSVG;
            l[i].children[1].innerHTML = "&nbsp;Image";

            var func = function(e)
            {
                var ll = document.querySelectorAll(ImageSelector);
                for (var ii in ll)
                {
                    if (!(ll[ii] instanceof Element)) continue;

                    if (getParent(ll[ii], 5) == getParent(this, 8))
                    {
                        e.stopPropagation();
                        this.href = ll[ii].src;
                    }
                }
            };

            //Better safe than sorry
            l[i].onmousedown = l[i].oncontextmenu = l[i].onmouseover = func;
        }
    }
})();