Scryfall - Image Hover [Art]

Hover over images to show the fullsize art image beside the mouse cursor.

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

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

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

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

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

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

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

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

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

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

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

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

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

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


    // ==UserScript==
    // @name         Scryfall - Image Hover [Art]
    // @namespace    http://tampermonkey.net/
    // @version      1.0
    // @description  Hover over images to show the fullsize art image beside the mouse cursor.
    // @author       Gondola#7671
    // @match        https://scryfall.com/*
    // @require      http://code.jquery.com/jquery-3.4.1.min.js
    // @compatible   firefox
    // @compatible   chrome
    // @run-at       document-idle
    // ==/UserScript==

    $(document).ready(function(){

        /*---START Image Hover---*/
        var mouse_offset_x = 16;
        var mouse_offset_y = 16;
        var container_y = 0;
        var mouse_side = false;
        var currentMousePos = { x: -1, y: -1 };


        $("body").append("<img id='img_hover_container' style='float:left; position:absolute; max-width:200px; overflow:hidden; z-index:9999;' src=''>")


        $(".card").mouseenter(function()
        {
            $("#img_hover_container").attr("src",$(this).attr('src').replace("normal","art_crop").replace("large","art_crop"))
            $("#img_hover_container").css("max-height",$(window).height())
        })


        $(".card").mouseleave(function()
        {
            $("#img_hover_container").attr("src","")
        })


        //Update Mouse Position
        $(document).mousemove(function(event)
        {
            currentMousePos.x = event.pageX;
            currentMousePos.y = event.pageY - $(document).scrollTop();
            update_pos();

            console.log("window height: " + $(window).height())
            console.log("currentMousePos.y: " +  currentMousePos.y)
        });


        function update_pos()
        {
            //Mouse Horizontal
            if(currentMousePos.x > ($(window).width()/2))
            {
                mouse_side = true;
                mouse_offset_x = -$("#img_hover_container").width() - 16;
                $("#img_hover_container").css("max-width", currentMousePos.x - 16)
            }
            else
            {
                mouse_side = false;
                mouse_offset_x = 16;
                $("#img_hover_container").css("max-width", $(window).width()-currentMousePos.x)
            }

            //Mouse Vertical
            if(currentMousePos.y > (($(window).height()) - $("#img_hover_container").height()) - 16)
            {
                container_y = $(document).scrollTop() + $(window).height() - $("#img_hover_container").height()
                console.log(mouse_offset_y)
            }
            else
            {
                container_y = currentMousePos.y + 16 + $(document).scrollTop() ;
            }

            $("#img_hover_container").offset({
                top: container_y,
                left: currentMousePos.x + mouse_offset_x
            });
        }


        //Update image position periodically
        var intervalID = setInterval(function(){update_pos();}, 100);

        $("#img_hover_container").css("max-height", $(window).height())
        /*---END Image Hover---*/

    });