IdleHacking hover popup

Open equipped item popup on hover

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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