IdleHacking hover popup

Open equipped item popup on hover

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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
    });
})();