IdleHacking hover popup

Open equipped item popup on hover

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Advertisement:

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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
    });
})();