Wowhead Tooltips on Reddit (Optimized)

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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
    });

})();