IdleHacking hover popup

Open equipped item popup on hover

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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