Search with google image fix

Search with google image again cause fuck google lens

当前为 2022-04-01 提交的版本,查看 最新版本

// ==UserScript==
// @name         Search with google image fix
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Search with google image again cause fuck google lens
// @author       You
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @match        http://*/*
// @match        https://*/*
// @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);
}

(function() {

    GM_addStyle(`
.container__menu {
                /* Absolute position */
                position: absolute;

                /* Reset */
                list-style: none;
                margin: 0;
                padding: 0;
                display: none;

                /* Misc */
                border: 1px solid #cbd5e0;
                border-radius: 0.25rem;
                background-color: #f7fafc;
            }
`);


    GM_addStyle(`
    .open {
    display: block;
}
`);

    GM_addStyle(`
.container__item {
                padding: 0.5rem 1rem;
                white-space: nowrap;
                cursor: pointer;
            }
`);

    GM_addStyle(`
 .container__item:hover {
                background-color: #bee3f8;
            }
`);

    GM_addStyle(`
.container__divider {
                border-bottom: 1px solid #cbd5e0;
                height: 1px;
            }
`);


    $("body").append(`
    <ul id="fucklens" class="container__menu">
                    <li class="container__item">Search with google image</li>
                </ul>
                `);

    var cntxtMn = $("#fucklens");
    var mouseX;
    var mouseY;
    var currentTarget = null;

    $(document).mousemove(function(e) {
        mouseX = e.pageX;
        mouseY = e.pageY;
    });
    $("img").on('contextmenu', displayContextMenu);

    function displayContextMenu(e) {
        // Prevent the browser from opening it's own context menu
        e.preventDefault();
        currentTarget = e.target;
        // Display the context menu;
        // Use mouse X and Y position data to open the menu where the right-click event occurred
        cntxtMn.css({'top':mouseY,'left':mouseX}).addClass("open");
    }
    cntxtMn.click(function(e) {
        // Stop propagation allows users to click on the menu without the click event 'bubbling over';
        // I.E: stops the below function (that hides the menu with a left-click anywhere on the page)
        // from affecting user interaction with the context menu
        e.stopPropagation();
    });

    $(document).click(function() {
        // Check if the context menu is open, and close it if it is (uses 'short-hand' if statement);
        // (conditionToTest) ? True Code : False Code;
        (cntxtMn.hasClass("open")) ? cntxtMn.removeClass("open") : false;
    });

    $(".container__item").click(function(){
        var src = "https://www.google.com/searchbyimage?image_url=" + $(currentTarget).prop("src");
        window.open(src);
    });

    /*  $(document).mousedown(function(event) {
        if ($(event.target).prop("tagName").toUpperCase() == "IMG"){
            if (window.event.shiftKey ){
                var origSrc = addHostInformationIfNeeded($(event.target).attr("src"));
                console.log("orig: " + origSrc);
                var src = "https://www.google.com/searchbyimage?image_url=" + origSrc;
                window.open(src);
                event.preventDefault();
                return false;
            }
        }
    });*/


})();