Dead Frontier Tooltip Details

Add information from the wiki in the weapons infobox

当前为 2025-05-07 提交的版本,查看 最新版本

// ==UserScript==
// @name         Dead Frontier Tooltip Details
// @author       ils94
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Add information from the wiki in the weapons infobox
// @match        https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=24
// @match        https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=25
// @match        https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=28*
// @match        https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=35
// @match        https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=50
// @match        https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=59
// @match        https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=82*
// @match        https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=84
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let dpsData = {};

    function loadDPS() {
        if (typeof window.weaponData === 'undefined') {
            console.error('[DPS] External weapon data not loaded');
            return;
        }

        window.weaponData.weapons.forEach(weapon => {
            const key = weapon.name.toLowerCase();
            dpsData[key] = {
                name: weapon.name,
                category: weapon.category,
                dps: weapon.stats.DPS || {},
                dph: weapon.stats.DPH || {},
                hps: weapon.stats.HPS || {},
                meleeRange: weapon.stats["Melee Range"] || null
            };
        });

        console.log('[DPS] Loaded', Object.keys(dpsData).length, 'entries from external JSON');
        startWatcher();
        injectDPSIntoStaticBoxes();
    }

    function generateStatsHTML(entry) {
        let statsHTML = `
            DPS: ${entry.dps.real || 'N/A'}<br>
            DPS Theoretical: ${entry.dps.theoretical || 'N/A'}<br>
            DPS Critical: ${entry.dps.critical || 'N/A'}<br>
            DPS Critical Theoretical: ${entry.dps.theoretical_critical || 'N/A'}<br>
            DPH: ${entry.dph.real || 'N/A'}<br>
            DPH Critical: ${entry.dph.critical || 'N/A'}<br>
            HPS: ${entry.hps.real || 'N/A'}<br>
            Theoretical HPS: ${entry.hps.theoretical || 'N/A'}
        `;
        if (entry.meleeRange) {
            statsHTML += `<br>Melee Range: ${entry.meleeRange.range || 'N/A'}<br>Cleave Width: ${entry.meleeRange.cleave_width || 'N/A'}`;
        }
        return statsHTML;
    }

    function startWatcher() {
        setInterval(() => {
            const box = document.getElementById('infoBox');
            if (!box || box.style.visibility === 'hidden') return;

            const nameEl = box.querySelector('.itemName');
            if (!nameEl) return;

            const weapon = nameEl.textContent.trim();
            const key = weapon.toLowerCase();
            const entry = dpsData[key];

            const old = box.querySelector('.dpsInjected');
            if (old) old.remove();
            const oldDisclaimer = box.querySelector('.dpsDisclaimer');
            if (oldDisclaimer) oldDisclaimer.remove();

            if (!entry) {
                console.log(`[DPS] ✗ ${weapon} (hover, no exact match)`);
                return;
            }

            const statsDiv = document.createElement('div');
            statsDiv.className = 'itemData dpsInjected';
            statsDiv.style.color = '#00FF00';
            statsDiv.innerHTML = generateStatsHTML(entry);
            box.appendChild(statsDiv);

            console.log(`[DPS] ✔ ${weapon} (hover)`);
        }, 1000);
    }

    function injectDPSIntoStaticBoxes() {
        const staticBoxes = document.querySelectorAll('.itemName');

        staticBoxes.forEach(nameEl => {
            const parent = nameEl.parentElement;
            if (!parent || parent.querySelector('.dpsInjected')) return;

            const weapon = nameEl.textContent.trim();
            const key = weapon.toLowerCase();
            const entry = dpsData[key];

            if (!entry) {
                console.log(`[DPS] ✗ ${weapon} (static, no exact match)`);
                return;
            }

            const statsDiv = document.createElement('div');
            statsDiv.className = 'itemData dpsInjected';
            statsDiv.style.color = '#00FF00';
            statsDiv.innerHTML = generateStatsHTML(entry);
            parent.appendChild(statsDiv);

            console.log(`[DPS] ✔ ${weapon} (static)`);
        });
    }

    function loadExternalScript() {
        const script = document.createElement('script');
        script.src = 'dead_frontier_weapons.js';
        script.onload = () => {
            console.log('[DPS] External JSON script loaded');
            loadDPS();
        };
        script.onerror = () => {
            console.error('[DPS] Failed to load external JSON script');
        };
        document.head.appendChild(script);
    }

    loadExternalScript();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址