Wowhead Tooltips on Reddit (Optimized)

Show Wowhead tooltips on Reddit with support for icons and dynamic loading.

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ć!)

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ć!)

// ==UserScript==
// @name         Wowhead Tooltips on Reddit (Optimized)
// @namespace    http://tampermonkey.net/
// @version      1.2
// @license      MIT
// @description  Show Wowhead tooltips on Reddit with support for icons and dynamic loading.
// @author       Nighthawk42 & Gemini
// @match        https://*.reddit.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 1. Configure Wowhead Tooltips
    // Customize these: iconizeLinks (shows item icons), colorLinks (rarity colors)
    window.whTooltips = {
        colorLinks: true,
        iconizeLinks: true,
        renameLinks: false,
        iconSize: 'small'
    };

    // 2. Inject Wowhead Power Script
    function initWowhead() {
        if (document.getElementById('wowhead-power-script')) return;
        const script = document.createElement('script');
        script.id = 'wowhead-power-script';
        script.src = 'https://wow.zamimg.com/widgets/power.js';
        script.async = true;
        document.head.appendChild(script);
    }

    // 3. Process Links
    function processWowheadLinks() {
        const links = document.querySelectorAll('a[href*="wowhead.com"]:not([data-wh-processed])');

        if (links.length === 0) return;

        links.forEach(link => {
            const href = link.href;
            link.setAttribute('data-wh-processed', 'true');

            // Map subdomains/paths to Wowhead versions
            if (href.includes('/beta/')) link.classList.add('wowhead-beta');
            else if (href.includes('/ptr/')) link.classList.add('wowhead-ptr');
            else if (href.includes('/classic/')) link.classList.add('wowhead-classic');
            else if (href.includes('/cata/')) link.classList.add('wowhead-cata');
            else if (href.includes('/tbc/')) link.classList.add('wowhead-tbc');
            else if (href.includes('/wotlk/')) link.classList.add('wowhead-wotlk');
            else link.classList.add('wowhead-live');

            // Force data-wowhead attribute to ensure the tooltip engine sees it
            link.setAttribute('data-wowhead', href);
        });

        // Tell Wowhead to scan the page for the new links we just labeled
        if (window.$WowheadPower) {
            window.$WowheadPower.refreshLinks();
        }
    }

    // 4. Execution Logic
    initWowhead();
    processWowheadLinks();

    // 5. Optimized Observer (Debounced)
    let debounceTimer;
    const observer = new MutationObserver(() => {
        clearTimeout(debounceTimer);
        debounceTimer = setTimeout(processWowheadLinks, 500); // Wait for scrolling/loading to pause
    });

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

})();