IdleHacking hover popup

Open equipped item popup on hover

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

Advertisement:

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

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

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

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

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

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

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

Advertisement:

// ==UserScript==
// @name         IdleHacking hover popup
// @namespace    http://tampermonkey.net/
// @version      1.01
// @description  Open equipped item popup on hover
// @match        *://*.idlehacking.com/*
// @match        *://idlehacking.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
    'use strict';

    let hoverTimer = null;
    let currentItem = null;
    let started = false;

    function init() {
        if (started) return;

        const panel = document.querySelector('#equipped-software-panel');
        if (!panel) return;

        started = true;
        console.log('[IdleHacking hover popup] init');

        function getItem(target) {
            return target?.closest('#equipped-software-panel .slot-content[data-item-id]');
        }

        function openPopup(item) {
            if (!item) return;
            if (currentItem === item) return;

            currentItem = item;

            item.dispatchEvent(new MouseEvent('mouseenter', {
                bubbles: true,
                cancelable: true,
                view: window
            }));

            item.dispatchEvent(new MouseEvent('mouseover', {
                bubbles: true,
                cancelable: true,
                view: window
            }));

            item.dispatchEvent(new MouseEvent('mousemove', {
                bubbles: true,
                cancelable: true,
                view: window
            }));

            item.dispatchEvent(new MouseEvent('click', {
                bubbles: true,
                cancelable: true,
                view: window
            }));
        }

        function closePopup() {
            if (!currentItem) return;

            document.dispatchEvent(new KeyboardEvent('keydown', {
                key: 'Escape',
                code: 'Escape',
                keyCode: 27,
                which: 27,
                bubbles: true
            }));

            currentItem = null;
        }

        document.addEventListener('mouseover', (e) => {
            const item = getItem(e.target);
            if (!item) return;

            clearTimeout(hoverTimer);
            hoverTimer = setTimeout(() => openPopup(item), 120);
        });

        document.addEventListener('mouseout', (e) => {
            const fromItem = getItem(e.target);
            const toItem = getItem(e.relatedTarget);

            if (fromItem && !toItem) {
                clearTimeout(hoverTimer);
                setTimeout(closePopup, 100);
            }
        });
    }

    init();

    const observer = new MutationObserver(() => {
        init();
    });

    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();