Wowhead Tooltips on Reddit

Show Wowhead tooltips on valid Reddit Wowhead links

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Wowhead Tooltips on Reddit
// @namespace    http://tampermonkey.net/
// @version      1.1
// @license      MIT
// @description  Show Wowhead tooltips on valid Reddit Wowhead links
// @author       Nighthawk42
// @match        https://*.reddit.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to add Wowhead script
    function addWowheadScript() {
        let script = document.createElement('script');
        script.src = 'https://wow.zamimg.com/widgets/power.js';
        script.async = true;
        document.head.appendChild(script);
    }

    // Add Wowhead script to the page
    addWowheadScript();

    // Function to process links and add wowhead-tooltip class
    function processWowheadLinks() {
        let links = document.querySelectorAll('a[href*="wowhead.com"]');
        links.forEach(link => {
            let href = link.href;
            link.setAttribute('data-wowhead', href);
            link.setAttribute('rel', 'external');

            // Determine the version from the URL and add corresponding attributes or classes
            if (href.includes('/beta/')) {
                link.classList.add('wowhead-beta');
            } else if (href.includes('/ptr-2/')) {
                link.classList.add('wowhead-ptr-2');
            } 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 {
                link.classList.add('wowhead-live');
            }
        });
    }

    // Process links on page load
    processWowheadLinks();

    // Listen for new links being added to the page (e.g., infinite scrolling)
    new MutationObserver(processWowheadLinks).observe(document.body, {
        childList: true,
        subtree: true
    });
})();