MWI Data Center

Milky Way Idle 统一数据管理:汉化、物品分类等,其他脚本通过 window.tmData 调用

Αυτός ο κώδικας δεν πρέπει να εγκατασταθεί άμεσα. Είναι μια βιβλιοθήκη για άλλους κώδικες που περιλαμβάνεται μέσω της οδηγίας meta // @require https://update.greasyfork.org/scripts/587836/1882278/MWI%20Data%20Center.js

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         【MWI】数据中心
// @version      1.0.0
// @description  Milky Way Idle 统一数据管理:汉化、物品分类等,其他脚本通过 window.tmData 调用
// @match        https://test.milkywayidle.com/*
// @icon         https://www.milkywayidle.com/favicon.svg
// @author       DelayNoMore
// @license      MIT
// @run-at       document-start
// @grant        none
// @namespace    http://tampermonkey.net/
// ==/UserScript==

(function () {
    'use strict';

    // 油猴多脚本@require单例检测:window对象跨脚本共享,只要存在window.tmData说明已经初始化过
    // 最开头就检查,防止同时加载导致都通过检测
    if (window.tmData) {
        return;
    }
    // 先把window.tmData占上,后面再补全属性,防止两个脚本同时检测时都通过
    window.tmData = { __isInitializing: true };

    // ==========================================
    // 汉化数据 (Chinese Translation)
    // ==========================================
    let ITEM_NAME_MAP = {}

    /**
     * 双向规范化物品ID映射:
     * 自动生成短ID(xxx) <-> 完整路径(/items/xxx) 的双向映射
     */
    function normalizeItemNameMap() {
        // 完整路径 -> 短ID
        Object.keys(ITEM_NAME_MAP).forEach(key => {
            if (key.startsWith('/items/')) {
                const shortId = key.split('/').pop();
                if (!ITEM_NAME_MAP[shortId]) {
                    ITEM_NAME_MAP[shortId] = ITEM_NAME_MAP[key];
                }
            }
        });
        // 短ID -> 完整路径
        Object.keys(ITEM_NAME_MAP).forEach(key => {
            if (!key.startsWith('/') && key.indexOf('/') === -1) {
                const fullPath = `/items/${key}`;
                if (!ITEM_NAME_MAP[fullPath]) {
                    ITEM_NAME_MAP[fullPath] = ITEM_NAME_MAP[key];
                }
            }
        });
    }

    /**
     * 自动从官方JS拉取最新汉化数据
     * @returns {Promise<boolean>} 是否成功拉取
     */
    async function fetchOfficialItemNames() {
        try {
            // 1. 从当前页面的script标签中找到包含itemNames的JS文件
            const scripts = Array.from(document.querySelectorAll('script[src]'));
            let jsUrl = null;
            
            for (const script of scripts) {
                if (script.src.includes('/static/js/') && script.src.match(/\/\d+\./) && script.src.endsWith('.js')) {
                    jsUrl = script.src;
                    break;
                }
            }

            if (!jsUrl) {
                console.warn('[数据中心] 未找到JS文件,跳过官方汉化拉取');
                return false;
            }

            // 2. 请求JS文件
            const response = await fetch(jsUrl, { cache: 'no-cache' });
            const jsContent = await response.text();

            // 3. 查找itemNames字典(使用括号深度匹配解决嵌套问题)
            const startMarker = 'itemNames:{';
            const startPos = jsContent.indexOf(startMarker);
            if (startPos < 0) throw new Error("未找到itemNames字段");

            const braceStart = startPos + startMarker.length - 1; // { 的位置
            let depth = 1;
            let endPos = braceStart + 1;
            while (endPos < jsContent.length && depth > 0) {
                const c = jsContent[endPos];
                if (c === '{') depth++;
                if (c === '}') depth--;
                endPos++;
            }

            if (depth !== 0) throw new Error("解析itemNames字典失败");

            const jsonStr = jsContent.substring(braceStart, endPos);
            const officialItemNames = JSON.parse(jsonStr);

            // 4. 完全替换为官方最新数据
            Object.keys(ITEM_NAME_MAP).forEach(k => delete ITEM_NAME_MAP[k]);
            Object.assign(ITEM_NAME_MAP, officialItemNames);

            // 5. 规范化映射(生成短ID和完整路径双向映射)
            normalizeItemNameMap();

            // 6. 重新构建强化字典
            g_enhancerDict = _buildDefaultEnhancerDict();

            console.log('[数据中心] 已成功拉取官方最新汉化数据,共' + Object.keys(officialItemNames).length + '条');
            return true;
        } catch (e) {
            console.warn('[数据中心] 拉取官方汉化失败,使用本地数据:', e.message);
            normalizeItemNameMap(); // 即使失败也要确保映射规范
            return false;
        }
    }

    // ==========================================
    // 物品分类数据 (Item Categories)
    // ==========================================
    const WIKI_CATEGORIES = {
        "Keys (钥匙与碎片)": ["blue_key_fragment", "green_key_fragment", "purple_key_fragment", "white_key_fragment", "orange_key_fragment", "brown_key_fragment", "stone_key_fragment", "dark_key_fragment", "burning_key_fragment", "chimerical_entry_key", "chimerical_chest_key", "sinister_entry_key", "sinister_chest_key", "enchanted_entry_key", "enchanted_chest_key", "pirate_entry_key", "pirate_chest_key"],
        "Food (食物)": ["donut", "blueberry_donut", "blackberry_donut", "strawberry_donut", "mooberry_donut", "marsberry_donut", "spaceberry_donut", "cupcake", "blueberry_cake", "blackberry_cake", "strawberry_cake", "mooberry_cake", "marsberry_cake", "spaceberry_cake", "gummy", "apple_gummy", "orange_gummy", "plum_gummy", "peach_gummy", "dragon_fruit_gummy", "star_fruit_gummy", "yogurt", "apple_yogurt", "orange_yogurt", "plum_yogurt", "peach_yogurt", "dragon_fruit_yogurt", "star_fruit_yogurt"],
        "Teas (茶)": ["milking_tea", "foraging_tea", "woodcutting_tea", "cooking_tea", "brewing_tea", "alchemy_tea", "enhancing_tea", "cheesesmithing_tea", "crafting_tea", "tailoring_tea", "super_milking_tea", "super_foraging_tea", "super_woodcutting_tea", "super_cooking_tea", "super_brewing_tea", "super_alchemy_tea", "super_enhancing_tea", "super_cheesesmithing_tea", "super_crafting_tea", "super_tailoring_tea", "ultra_milking_tea", "ultra_foraging_tea", "ultra_woodcutting_tea", "ultra_cooking_tea", "ultra_brewing_tea", "ultra_alchemy_tea", "ultra_enhancing_tea", "ultra_cheesesmithing_tea", "ultra_crafting_tea", "ultra_tailoring_tea", "gathering_tea", "gourmet_tea", "wisdom_tea", "processing_tea", "efficiency_tea", "artisan_tea", "catalytic_tea", "blessed_tea"],
        "Coffees (咖啡)": ["stamina_coffee", "intelligence_coffee", "defense_coffee", "attack_coffee", "melee_coffee", "ranged_coffee", "magic_coffee", "super_stamina_coffee", "super_intelligence_coffee", "super_defense_coffee", "super_attack_coffee", "super_melee_coffee", "super_ranged_coffee", "super_magic_coffee", "ultra_stamina_coffee", "ultra_intelligence_coffee", "ultra_defense_coffee", "ultra_attack_coffee", "ultra_melee_coffee", "ultra_ranged_coffee", "ultra_magic_coffee", "wisdom_coffee", "lucky_coffee", "swiftness_coffee", "channeling_coffee", "critical_coffee"],
        "Books (技能书)": ["poke", "impale", "puncture", "penetrating_strike", "scratch", "cleave", "maim", "crippling_slash", "smack", "sweep", "stunning_blow", "fracturing_impact", "shield_bash", "quick_shot", "aqua_arrow", "flame_arrow", "rain_of_arrows", "silencing_shot", "steady_shot", "pestilent_shot", "penetrating_shot", "water_strike", "ice_spear", "frost_surge", "mana_spring", "entangle", "toxic_pollen", "natures_veil", "life_drain", "fireball", "flame_blast", "firestorm", "smoke_burst", "minor_heal", "heal", "quick_aid", "rejuvenate", "taunt", "provoke", "toughness", "elusiveness", "precision", "berserk", "elemental_affinity", "frenzy", "spike_shell", "retribution", "vampirism", "revive", "insanity", "invincible", "speed_aura", "guardian_aura", "fierce_aura", "critical_aura", "mystic_aura"],
        "Equipment - Main Hand (主手)": ["gobo_stabber", "gobo_slasher", "gobo_smasher", "spiked_bulwark", "werewolf_slasher", "griffin_bulwark", "griffin_bulwark_refined", "gobo_shooter", "vampiric_bow", "cursed_bow", "cursed_bow_refined", "gobo_boomstick", "cheese_bulwark", "verdant_bulwark", "azure_bulwark", "burble_bulwark", "crimson_bulwark", "rainbow_bulwark", "holy_bulwark", "wooden_bow", "birch_bow", "cedar_bow", "purpleheart_bow", "ginkgo_bow", "redwood_bow", "arcane_bow", "stalactite_spear", "granite_bludgeon", "furious_spear", "furious_spear_refined", "regal_sword", "regal_sword_refined", "chaotic_flail", "chaotic_flail_refined", "soul_hunter_crossbow", "sundering_crossbow", "sundering_crossbow_refined", "frost_staff", "infernal_battlestaff", "jackalope_staff", "rippling_trident", "rippling_trident_refined", "blooming_trident", "blooming_trident_refined", "blazing_trident", "blazing_trident_refined", "cheese_sword", "verdant_sword", "azure_sword", "burble_sword", "crimson_sword", "rainbow_sword", "holy_sword", "cheese_spear", "verdant_spear", "azure_spear", "burble_spear", "crimson_spear", "rainbow_spear", "holy_spear", "cheese_mace", "verdant_mace", "azure_mace", "burble_mace", "crimson_mace", "rainbow_mace", "holy_mace", "wooden_crossbow", "birch_crossbow", "cedar_crossbow", "purpleheart_crossbow", "ginkgo_crossbow", "redwood_crossbow", "arcane_crossbow", "wooden_water_staff", "birch_water_staff", "cedar_water_staff", "purpleheart_water_staff", "ginkgo_water_staff", "redwood_water_staff", "arcane_water_staff", "wooden_nature_staff", "birch_nature_staff", "cedar_nature_staff", "purpleheart_nature_staff", "ginkgo_nature_staff", "redwood_nature_staff", "arcane_nature_staff", "wooden_fire_staff", "birch_fire_staff", "cedar_fire_staff", "purpleheart_fire_staff", "ginkgo_fire_staff", "redwood_fire_staff", "arcane_fire_staff"],
        "Equipment - Off Hand (副手)": ["eye_watch", "snake_fang_dirk", "vision_shield", "gobo_defender", "vampire_fang_dirk", "knights_aegis", "knights_aegis_refined", "treant_shield", "manticore_shield", "tome_of_healing", "tome_of_the_elements", "watchful_relic", "bishops_codex", "bishops_codex_refined", "cheese_buckler", "verdant_buckler", "azure_buckler", "burble_buckler", "crimson_buckler", "rainbow_buckler", "holy_buckler", "wooden_shield", "birch_shield", "cedar_shield", "purpleheart_shield", "ginkgo_shield", "redwood_shield", "arcane_shield"],
        "Equipment - Back (背部)": ["gatherer_cape", "gatherer_cape_refined", "artificer_cape", "artificer_cape_refined", "culinary_cape", "culinary_cape_refined", "chance_cape", "chance_cape_refined", "sinister_cape", "sinister_cape_refined", "chimerical_quiver", "chimerical_quiver_refined", "enchanted_cloak", "enchanted_cloak_refined"],
        "Equipment - Head (头部)": ["red_culinary_hat", "snail_shell_helmet", "vision_helmet", "fluffy_red_hat", "corsair_helmet", "corsair_helmet_refined", "acrobatic_hood", "acrobatic_hood_refined", "magicians_hat", "magicians_hat_refined", "cheese_helmet", "verdant_helmet", "azure_helmet", "burble_helmet", "crimson_helmet", "rainbow_helmet", "holy_helmet", "rough_hood", "reptile_hood", "gobo_hood", "beast_hood", "umbral_hood", "cotton_hat", "linen_hat", "bamboo_hat", "silk_hat", "radiant_hat"],
        "Equipment - Body (胸甲)": ["dairyhands_top", "foragers_top", "lumberjacks_top", "cheesemakers_top", "crafters_top", "tailors_top", "chefs_top", "brewers_top", "alchemists_top", "enhancers_top", "gator_vest", "turtle_shell_body", "colossus_plate_body", "demonic_plate_body", "anchorbound_plate_body", "anchorbound_plate_body_refined", "maelstrom_plate_body", "maelstrom_plate_body_refined", "marine_tunic", "revenant_tunic", "griffin_tunic", "kraken_tunic", "kraken_tunic_refined", "icy_robe_top", "flaming_robe_top", "luna_robe_top", "royal_water_robe_top", "royal_water_robe_top_refined", "royal_nature_robe_top", "royal_nature_robe_top_refined", "royal_fire_robe_top", "royal_fire_robe_top_refined", "cheese_plate_body", "verdant_plate_body", "azure_plate_body", "burble_plate_body", "crimson_plate_body", "rainbow_plate_body", "holy_plate_body", "rough_tunic", "reptile_tunic", "gobo_tunic", "beast_tunic", "umbral_tunic", "cotton_robe_top", "linen_robe_top", "bamboo_robe_top", "silk_robe_top", "radiant_robe_top"],
        "Equipment - Legs (腿甲)": ["dairyhands_bottoms", "foragers_bottoms", "lumberjacks_bottoms", "cheesemakers_bottoms", "crafters_bottoms", "tailors_bottoms", "chefs_bottoms", "brewers_bottoms", "alchemists_bottoms", "enhancers_bottoms", "turtle_shell_legs", "colossus_plate_legs", "demonic_plate_legs", "anchorbound_plate_legs", "anchorbound_plate_legs_refined", "maelstrom_plate_legs", "maelstrom_plate_legs_refined", "marine_chaps", "revenant_chaps", "griffin_chaps", "kraken_chaps", "kraken_chaps_refined", "icy_robe_bottoms", "flaming_robe_bottoms", "luna_robe_bottoms", "royal_water_robe_bottoms", "royal_water_robe_bottoms_refined", "royal_nature_robe_bottoms", "royal_nature_robe_bottoms_refined", "royal_fire_robe_bottoms", "royal_fire_robe_bottoms_refined", "cheese_plate_legs", "verdant_plate_legs", "azure_plate_legs", "burble_plate_legs", "crimson_plate_legs", "rainbow_plate_legs", "holy_plate_legs", "rough_chaps", "reptile_chaps", "gobo_chaps", "beast_chaps", "umbral_chaps", "cotton_robe_bottoms", "linen_robe_bottoms", "bamboo_robe_bottoms", "silk_robe_bottoms", "radiant_robe_bottoms"],
        "Equipment - Hands (护手)": ["enchanted_gloves", "pincer_gloves", "panda_gloves", "magnetic_gloves", "dodocamel_gauntlets", "dodocamel_gauntlets_refined", "sighted_bracers", "marksman_bracers", "marksman_bracers_refined", "chrono_gloves", "cheese_gauntlets", "verdant_gauntlets", "azure_gauntlets", "burble_gauntlets", "crimson_gauntlets", "rainbow_gauntlets", "holy_gauntlets", "rough_bracers", "reptile_bracers", "gobo_bracers", "beast_bracers", "umbral_bracers", "cotton_gloves", "linen_gloves", "bamboo_gloves", "silk_gloves", "radiant_gloves"],
        "Equipment - Feet (鞋靴)": ["collectors_boots", "shoebill_shoes", "black_bear_shoes", "grizzly_bear_shoes", "polar_bear_shoes", "pathbreaker_boots", "pathbreaker_boots_refined", "centaur_boots", "pathfinder_boots", "pathfinder_boots_refined", "sorcerer_boots", "pathseeker_boots", "pathseeker_boots_refined", "cheese_boots", "verdant_boots", "azure_boots", "burble_boots", "crimson_boots", "rainbow_boots", "holy_boots", "rough_boots", "reptile_boots", "gobo_boots", "beast_boots", "umbral_boots", "cotton_boots", "linen_boots", "bamboo_boots", "silk_boots", "radiant_boots"],
        "Equipment - Pouch (行囊)": ["small_pouch", "medium_pouch", "large_pouch", "giant_pouch", "gluttonous_pouch", "guzzling_pouch"],
        "Equipment - Jewelry (首饰)": ["necklace_of_efficiency", "fighter_necklace", "ranger_necklace", "wizard_necklace", "necklace_of_wisdom", "necklace_of_speed", "philosophers_necklace", "earrings_of_gathering", "earrings_of_essence_find", "earrings_of_armor", "earrings_of_regeneration", "earrings_of_resistance", "earrings_of_rare_find", "earrings_of_critical_strike", "philosophers_earrings", "ring_of_gathering", "ring_of_essence_find", "ring_of_armor", "ring_of_regeneration", "ring_of_resistance", "ring_of_rare_find", "ring_of_critical_strike", "philosophers_ring"],
        "Equipment - Charms (护符)": ["trainee_milking_charm", "basic_milking_charm", "advanced_milking_charm", "expert_milking_charm", "master_milking_charm", "grandmaster_milking_charm", "trainee_foraging_charm", "basic_foraging_charm", "advanced_foraging_charm", "expert_foraging_charm", "master_foraging_charm", "grandmaster_foraging_charm", "trainee_woodcutting_charm", "basic_woodcutting_charm", "advanced_woodcutting_charm", "expert_woodcutting_charm", "master_woodcutting_charm", "grandmaster_woodcutting_charm", "trainee_cheesesmithing_charm", "basic_cheesesmithing_charm", "advanced_cheesesmithing_charm", "expert_cheesesmithing_charm", "master_cheesesmithing_charm", "grandmaster_cheesesmithing_charm", "trainee_crafting_charm", "basic_crafting_charm", "advanced_crafting_charm", "expert_crafting_charm", "master_crafting_charm", "grandmaster_crafting_charm", "trainee_tailoring_charm", "basic_tailoring_charm", "advanced_tailoring_charm", "expert_tailoring_charm", "master_tailoring_charm", "grandmaster_tailoring_charm", "trainee_cooking_charm", "basic_cooking_charm", "advanced_cooking_charm", "expert_cooking_charm", "master_cooking_charm", "grandmaster_cooking_charm", "trainee_brewing_charm", "basic_brewing_charm", "advanced_brewing_charm", "expert_brewing_charm", "master_brewing_charm", "grandmaster_brewing_charm", "trainee_alchemy_charm", "basic_alchemy_charm", "advanced_alchemy_charm", "expert_alchemy_charm", "master_alchemy_charm", "grandmaster_alchemy_charm", "trainee_enhancing_charm", "basic_enhancing_charm", "advanced_enhancing_charm", "expert_enhancing_charm", "master_enhancing_charm", "grandmaster_enhancing_charm", "trainee_stamina_charm", "basic_stamina_charm", "advanced_stamina_charm", "expert_stamina_charm", "master_stamina_charm", "grandmaster_stamina_charm", "trainee_intelligence_charm", "basic_intelligence_charm", "advanced_intelligence_charm", "expert_intelligence_charm", "master_intelligence_charm", "grandmaster_intelligence_charm", "trainee_attack_charm", "basic_attack_charm", "advanced_attack_charm", "expert_attack_charm", "master_attack_charm", "grandmaster_attack_charm", "trainee_defense_charm", "basic_defense_charm", "advanced_defense_charm", "expert_defense_charm", "master_defense_charm", "grandmaster_defense_charm", "trainee_melee_charm", "basic_melee_charm", "advanced_melee_charm", "expert_melee_charm", "master_melee_charm", "grandmaster_melee_charm", "trainee_ranged_charm", "basic_ranged_charm", "advanced_ranged_charm", "expert_ranged_charm", "master_ranged_charm", "grandmaster_ranged_charm", "trainee_magic_charm", "basic_magic_charm", "advanced_magic_charm", "expert_magic_charm", "master_magic_charm", "grandmaster_magic_charm"],
        "Equipment - Trinket (徽章)": ["basic_task_badge", "advanced_task_badge", "expert_task_badge"],
        "Equipment - Tools (工具)": ["celestial_brush", "cheese_brush", "verdant_brush", "azure_brush", "burble_brush", "crimson_brush", "rainbow_brush", "holy_brush", "celestial_shears", "cheese_shears", "verdant_shears", "azure_shears", "burble_shears", "crimson_shears", "rainbow_shears", "holy_shears", "celestial_hatchet", "cheese_hatchet", "verdant_hatchet", "azure_hatchet", "burble_hatchet", "crimson_hatchet", "rainbow_hatchet", "holy_hatchet", "celestial_hammer", "cheese_hammer", "verdant_hammer", "azure_hammer", "burble_hammer", "crimson_hammer", "rainbow_hammer", "holy_hammer", "celestial_chisel", "cheese_chisel", "verdant_chisel", "azure_chisel", "burble_chisel", "crimson_chisel", "rainbow_chisel", "holy_chisel", "celestial_needle", "cheese_needle", "verdant_needle", "azure_needle", "burble_needle", "crimson_needle", "rainbow_needle", "holy_needle", "celestial_spatula", "cheese_spatula", "verdant_spatula", "azure_spatula", "burble_spatula", "crimson_spatula", "rainbow_spatula", "holy_spatula", "celestial_pot", "cheese_pot", "verdant_pot", "azure_pot", "burble_pot", "crimson_pot", "rainbow_pot", "holy_pot", "celestial_alembic", "cheese_alembic", "verdant_alembic", "azure_alembic", "burble_alembic", "crimson_alembic", "rainbow_alembic", "holy_alembic", "celestial_enhancer", "cheese_enhancer", "verdant_enhancer", "azure_enhancer", "burble_enhancer", "crimson_enhancer", "rainbow_enhancer", "holy_enhancer"],
        "Resources (奶与奶酪)": ["milk", "verdant_milk", "azure_milk", "burble_milk", "crimson_milk", "rainbow_milk", "holy_milk", "cheese", "verdant_cheese", "azure_cheese", "burble_cheese", "crimson_cheese", "rainbow_cheese", "holy_cheese"],
        "Resources (原木与木材)": ["log", "birch_log", "cedar_log", "purpleheart_log", "ginkgo_log", "redwood_log", "arcane_log", "lumber", "birch_lumber", "cedar_lumber", "purpleheart_lumber", "ginkgo_lumber", "redwood_lumber", "arcane_lumber"],
        "Resources (皮革与布料)": ["rough_hide", "reptile_hide", "gobo_hide", "beast_hide", "umbral_hide", "rough_leather", "reptile_leather", "gobo_leather", "beast_leather", "umbral_leather", "cotton", "flax", "bamboo_branch", "cocoon", "radiant_fiber", "cotton_fabric", "linen_fabric", "bamboo_fabric", "silk_fabric", "radiant_fabric"],
        "Resources (农作物与茶叶)": ["egg", "wheat", "sugar", "blueberry", "blackberry", "strawberry", "mooberry", "marsberry", "spaceberry", "apple", "orange", "plum", "peach", "dragon_fruit", "star_fruit", "arabica_coffee_bean", "robusta_coffee_bean", "liberica_coffee_bean", "excelsa_coffee_bean", "fieriosa_coffee_bean", "spacia_coffee_bean", "green_tea_leaf", "black_tea_leaf", "burble_tea_leaf", "moolong_tea_leaf", "red_tea_leaf", "emp_tea_leaf"],
        "Resources (怪物掉落与杂项)": ["catalyst_of_coinification", "catalyst_of_decomposition", "catalyst_of_transmutation", "prime_catalyst", "snake_fang", "shoebill_feather", "snail_shell", "crab_pincer", "turtle_shell", "marine_scale", "treant_bark", "centaur_hoof", "luna_wing", "gobo_rag", "goggles", "magnifying_glass", "eye_of_the_watcher", "icy_cloth", "flaming_cloth", "sorcerers_sole", "chrono_sphere", "frost_sphere", "panda_fluff", "black_bear_fluff", "grizzly_bear_fluff", "polar_bear_fluff", "red_panda_fluff", "magnet", "stalactite_shard", "living_granite", "colossus_core", "vampire_fang", "werewolf_claw", "revenant_anima", "soul_fragment", "infernal_ember", "demonic_core", "griffin_leather", "manticore_sting", "jackalope_antler", "dodocamel_plume", "griffin_talon", "chimerical_refinement_shard", "acrobats_ribbon", "magicians_cloth", "chaotic_chain", "cursed_ball", "sinister_refinement_shard", "royal_cloth", "knights_ingot", "bishops_scroll", "regal_jewel", "sundering_jewel", "enchanted_refinement_shard", "marksman_brooch", "corsair_crest", "damaged_anchor", "maelstrom_plating", "kraken_leather", "kraken_fang", "pirate_refinement_shard", "pathbreaker_lodestone", "pathfinder_lodestone", "pathseeker_lodestone", "labyrinth_refinement_shard", "butter_of_proficiency", "thread_of_expertise", "branch_of_insight"],
        "Resources (精华)": ["gluttonous_energy", "guzzling_energy", "milking_essence", "foraging_essence", "woodcutting_essence", "cheesesmithing_essence", "crafting_essence", "tailoring_essence", "cooking_essence", "brewing_essence", "alchemy_essence", "enhancing_essence", "swamp_essence", "aqua_essence", "jungle_essence", "gobo_essence", "eyessence", "sorcerer_essence", "bear_essence", "golem_essence", "twilight_essence", "abyssal_essence", "chimerical_essence", "sinister_essence", "enchanted_essence", "pirate_essence", "labyrinth_essence"],
        "Resources (宝石)": ["task_crystal", "star_fragment", "pearl", "amber", "garnet", "jade", "amethyst", "moonstone", "sunstone", "philosophers_stone", "crushed_pearl", "crushed_amber", "crushed_garnet", "crushed_jade", "crushed_amethyst", "crushed_moonstone", "crushed_sunstone", "crushed_philosophers_stone", "shard_of_protection", "mirror_of_protection", "philosophers_mirror"],
        "Labyrinth Items (迷宫道具)": ["basic_torch", "advanced_torch", "expert_torch", "basic_shroud", "advanced_shroud", "expert_shroud", "basic_beacon", "advanced_beacon", "expert_beacon", "basic_food_crate", "advanced_food_crate", "expert_food_crate", "basic_tea_crate", "advanced_tea_crate", "expert_tea_crate", "basic_coffee_crate", "advanced_coffee_crate", "expert_coffee_crate"]
    };

    const FLAT_WIKI_GROUPS = Object.entries(WIKI_CATEGORIES).map(([catName, itemIds]) => {
        return { name: catName, items: itemIds };
    });

    // ==========================================
    // 商店物品数据 (Shop Items Data)
    // ==========================================
    /**
     * 商店物品列表(手动维护,格式:[{id, name, price}, ...])
     * 你可以直接在这里填写商店数据,或者通过 window.tmData.updateShopData() 方法更新
     */
    let SHOP_ITEMS = [
        // ===== 请在这里填入商店数据,格式示例:=====
        // { "id": "blue_key_fragment", "name": "蓝色钥匙碎片", "price": "30,000 金币" },
        // { "id": "green_key_fragment", "name": "绿色钥匙碎片", "price": "30,000 金币" },
        // ===== 数据粘贴在下面 =====
        

    ];

    /** 物品ID->价格数字映射表(自动从SHOP_ITEMS计算生成) */
    let SHOP_PRICE_MAP = {};

    /**
     * (重新)构建价格映射表
     */
    function _buildShopPriceMap() {
        SHOP_PRICE_MAP = {};
        SHOP_ITEMS.forEach(item => {
            let priceInt = 0;
            if (typeof item.price === 'string') {
                priceInt = parseInt(item.price.replace(/,/g, '')) || 0;
            } else if (typeof item.price === 'number') {
                priceInt = item.price;
            }
            SHOP_PRICE_MAP[item.id] = priceInt;
        });
    }
    // 初始构建一次
    _buildShopPriceMap();

    // 尝试从 localStorage 读取已保存的商店数据(兼容旧版)
    try {
        const localShopData = localStorage.getItem('tm_milky_shop_data_v2');
        if (localShopData) {
            const parsed = JSON.parse(localShopData);
            if (Array.isArray(parsed) && parsed.length > 0) {
                SHOP_ITEMS = parsed;
                _buildShopPriceMap();
                console.log('[数据中心] 从localStorage加载商店数据,共' + parsed.length + '条');
            }
        }
    } catch(e) {
        console.warn('[数据中心] 加载localStorage商店数据失败:', e.message);
    }

    /**
     * 自动从商店页面DOM抓取最新商店数据
     * 原理:商店页面渲染了所有可购买物品,包含物品ID(图标svg的use href)、中文名、价格
     * 只抓取从"蓝色钥匙碎片"开始到最后的物品(跳过前面不推荐的物品)
     */
    function autoFetchShopDataFromDOM() {
        try {
            const allShopItems = document.querySelectorAll('[class*="ShopPanel_shopItem"]');
            if (allShopItems.length === 0) return false;

            // 找到"蓝色钥匙碎片"作为起始标记(版本更新不会变)
            let startIndex = -1;
            for (let i = 0; i < allShopItems.length; i++) {
                const nameEl = allShopItems[i].querySelector('[class*="ShopPanel_name"]');
                const name = nameEl ? nameEl.innerText.trim() : '';
                if (name === '蓝色钥匙碎片') {
                    startIndex = i;
                    break;
                }
            }
            if (startIndex === -1) return false; // 没找到起始标记,可能不在商店测试页

            const shopItems = Array.from(allShopItems).slice(startIndex);
            const results = [];
            const seen = new Set();

            shopItems.forEach((item) => {
                const nameEl = item.querySelector('[class*="ShopPanel_name"]');
                const name = nameEl ? nameEl.innerText.trim() : '';
                const costEl = item.querySelector('[class*="ShopPanel_costs"]');
                const priceText = costEl ? costEl.innerText.trim() : '';

                // 从SVG的use href提取物品ID
                let itemId = '';
                const containerEl = item.querySelector('[class*="ShopPanel_itemContainer"]');
                if (containerEl) {
                    const useEl = containerEl.querySelector('use[href]');
                    if (useEl) {
                        const href = useEl.getAttribute('href') || '';
                        const match = href.match(/#([a-z0-9_]+)$/);
                        if (match) itemId = match[1];
                    }
                }
                if (!itemId || !name) return;
                if (seen.has(itemId)) return;
                seen.add(itemId);
                results.push({ id: itemId, name: name, price: priceText });
            });

            if (results.length === 0) return false;

            // 更新内存 + localStorage(通过updateShopData API,会自动触发事件)
            SHOP_ITEMS = results;
            _buildShopPriceMap();
            try { localStorage.setItem('tm_milky_shop_data_v2', JSON.stringify(SHOP_ITEMS)); } catch(e) {}
            window.dispatchEvent(new CustomEvent('tmData:shopUpdated'));
            console.log('[数据中心] 自动从商店页面抓取数据成功,共' + results.length + '条');
            return true;
        } catch(e) {
            console.warn('[数据中心] 自动抓取商店数据失败:', e.message);
            return false;
        }
    }

    // 暴露自动抓取函数,供外部调用
    window.tmAutoFetchShopData = autoFetchShopDataFromDOM;

    // 用MutationObserver监听商店页面渲染,自动触发抓取
    function setupShopDOMObserver() {
        let hasFetchedThisSession = false;
        const observer = new MutationObserver(() => {
            if (hasFetchedThisSession) return;
            // 检测商店面板是否渲染
            const shopPanel = document.querySelector('[class*="ShopPanel_shopItem"]');
            if (shopPanel) {
                // 延迟一下确保所有物品都渲染完
                setTimeout(() => {
                    if (!hasFetchedThisSession) {
                        hasFetchedThisSession = true;
                        autoFetchShopDataFromDOM();
                        // 继续监听,离开商店页再进来时重新抓取
                        setTimeout(() => { hasFetchedThisSession = false; }, 5000);
                    }
                }, 800);
            }
        });
        // 等 body 出现后开始监听
        function startObserve() {
            if (document.body) {
                observer.observe(document.body, { childList: true, subtree: true });
            } else {
                setTimeout(startObserve, 100);
            }
        }
        startObserve();
    }
    setupShopDOMObserver();

    // ==========================================
    // 系统常量 (Constants)
    // ==========================================
    //9c39e2ec
    const SPRITE_URL = "/static/media/items_sprite.f58c9476.svg";
    const KEY_CN_DATA = 'tm_milky_cn_data_v2';


    /**
     * 获取物品中文名
     * @param {string} itemHrid - 物品 hrid 或短ID
     * @returns {string} 中文名或原名
     */
    function getChineseName(itemHrid) {
        if (!itemHrid) return "未知物品";
        if (ITEM_NAME_MAP[itemHrid]) return ITEM_NAME_MAP[itemHrid];
        const shortId = itemHrid.split('/').pop();
        if (ITEM_NAME_MAP[shortId]) return ITEM_NAME_MAP[shortId];
        return shortId;
    }

    /**
     * 全局 API:更新汉化数据(仅更新内存,不写入 localStorage)
     * 永久修改请直接编辑本脚本顶部的 CN_DATA_STR
     * @param {string} str - 汉化映射字符串
     */
    window.tmUpdateCn = function (str) {
        // 只更新内存,不写 localStorage
        ITEM_NAME_MAP = {};
        if (str) {
            str.split('|').forEach(entry => {
                const parts = entry.split(':');
                if (parts.length >= 2) {
                    ITEM_NAME_MAP[parts[0]] = parts[1];
                    ITEM_NAME_MAP[`/items/${parts[0]}`] = parts[1];
                }
            });
        }
        // 触发自定义事件,通知其他脚本汉化数据已更新
        window.dispatchEvent(new CustomEvent('tmData:cnUpdated'));
    };

    // ==========================================
    // 强化助手共享数据管理 (Enhancer Shared Data)
    // 管理:装备汉化字典、装备保护映射、强化配装存档
    // ==========================================
    const ENHANCER_KEYS = {
        DICT: 'DNM_装备列表',
        MAP: 'DNM_装备保护映射',
        LOADOUTS: 'DNM_强化配装存档'
    };

    /**
     * 构建默认装备字典
     * 从 WIKI_CATEGORIES 中的装备分类自动提取所有可强化装备,
     * key=装备短ID,value=中文名(从 ITEM_NAME_MAP 获取)
     */
    function _buildDefaultEnhancerDict() {
        const dict = {};
        const EQUIP_CATS = [
            'Equipment - Main Hand (主手)',
            'Equipment - Off Hand (副手)',
            'Equipment - Back (背部)',
            'Equipment - Head (头部)',
            'Equipment - Body (胸甲)',
            'Equipment - Legs (腿甲)',
            'Equipment - Hands (护手)',
            'Equipment - Feet (鞋靴)',
            'Equipment - Jewelry (首饰)',
            'Equipment - Pouch (行囊)',
            'Equipment - Tools (工具)',
            'Equipment - Charms (护符)',
            'Equipment - Trinket (徽章)'
        ];
        EQUIP_CATS.forEach(cat => {
            const items = WIKI_CATEGORIES[cat];
            if (!items) return;
            items.forEach(id => {
                dict[id] = ITEM_NAME_MAP[id] || id;
            });
        });
        return dict;
    }

    /** 默认保护映射(空对象 = 全部使用默认护心镜) */
    const DEFAULT_ENHANCER_MAP = {
        "cotton_hat": "cotton_hat",
        "cotton_boots": "cotton_boots",
        "wooden_shield": "wooden_shield",
        "wooden_bow": "wooden_bow",
        "wooden_crossbow": "wooden_crossbow",
        "silk_hat": "silk_hat",
        "silk_boots": "silk_boots",
        "bamboo_hat": "bamboo_hat",
        "bamboo_boots": "bamboo_boots",
        "umbral_boots": "umbral_boots",
        "rainbow_pot": "rainbow_pot",
        "rainbow_sword": "rainbow_sword",
        "rainbow_boots": "rainbow_boots",
        "rainbow_needle": "rainbow_needle",
        "rough_boots": "rough_boots",
        "verdant_pot": "verdant_pot",
        "verdant_sword": "verdant_sword",
        "verdant_boots": "verdant_boots",
        "verdant_needle": "verdant_needle",
        "large_pouch": "large_pouch",
        "radiant_hat": "radiant_hat",
        "radiant_boots": "radiant_boots",
        "black_bear_shoes": "black_bear_fluff",
        "redwood_shield": "redwood_shield",
        "redwood_bow": "redwood_bow",
        "redwood_crossbow": "redwood_crossbow",
        "birch_shield": "birch_shield",
        "birch_bow": "birch_bow",
        "birch_crossbow": "birch_crossbow",
        "crimson_pot": "crimson_pot",
        "crimson_sword": "crimson_sword",
        "crimson_boots": "crimson_boots",
        "crimson_needle": "crimson_needle",
        "cotton_robe_top": "cotton_robe_top",
        "cotton_robe_bottoms": "cotton_robe_bottoms",
        "cotton_gloves": "cotton_gloves",
        "cheese_pot": "cheese_pot",
        "cheese_sword": "cheese_sword",
        "cheese_boots": "cheese_boots",
        "cheese_needle": "cheese_needle",
        "knights_aegis": "knights_ingot",
        "burble_pot": "burble_pot",
        "burble_sword": "burble_sword",
        "burble_boots": "burble_boots",
        "burble_needle": "burble_needle",
        "arcane_shield": "arcane_shield",
        "arcane_bow": "arcane_bow",
        "arcane_crossbow": "arcane_crossbow",
        "holy_pot": "holy_pot",
        "holy_sword": "holy_sword",
        "holy_boots": "holy_boots",
        "holy_needle": "holy_needle",
        "vision_shield": "magnifying_glass",
        "treant_shield": "treant_bark",
        "silk_gloves": "silk_gloves",
        "azure_pot": "azure_pot",
        "azure_sword": "azure_sword",
        "azure_boots": "azure_boots",
        "azure_needle": "azure_needle",
        "sorcerer_boots": "sorcerers_sole",
        "vampiric_bow": "vampire_fang",
        "small_pouch": "small_pouch",
        "manticore_shield": "manticore_sting",
        "celestial_pot": "butter_of_proficiency",
        "celestial_needle": "butter_of_proficiency",
        "cedar_shield": "cedar_shield",
        "cedar_bow": "cedar_bow",
        "cedar_crossbow": "cedar_crossbow",
        "linen_hat": "linen_hat",
        "linen_boots": "linen_boots",
        "beast_boots": "beast_boots",
        "ginkgo_shield": "ginkgo_shield",
        "ginkgo_bow": "ginkgo_bow",
        "ginkgo_crossbow": "ginkgo_crossbow",
        "medium_pouch": "medium_pouch",
        "bamboo_robe_top": "bamboo_robe_top",
        "bamboo_robe_bottoms": "bamboo_robe_bottoms",
        "bamboo_gloves": "bamboo_gloves",
        "purpleheart_shield": "purpleheart_shield",
        "purpleheart_bow": "purpleheart_bow",
        "purpleheart_crossbow": "purpleheart_crossbow",
        "grizzly_bear_shoes": "grizzly_bear_fluff",
        "umbral_hood": "umbral_hood",
        "umbral_bracers": "umbral_bracers",
        "umbral_chaps": "umbral_chaps",
        "umbral_tunic": "umbral_tunic",
        "centaur_boots": "centaur_hoof",
        "earrings_of_critical_strike": "earrings_of_critical_strike",
        "ring_of_critical_strike": "ring_of_critical_strike",
        "guzzling_pouch": "mirror_of_protection",
        "polar_bear_shoes": "polar_bear_fluff",
        "frost_staff": "frost_sphere",
        "icy_robe_top": "icy_cloth",
        "icy_robe_bottoms": "icy_cloth",
        "tailors_top": "thread_of_expertise",
        "tailors_bottoms": "thread_of_expertise",
        "earrings_of_gathering": "earrings_of_gathering",
        "ring_of_gathering": "ring_of_gathering",
        "rainbow_hammer": "rainbow_hammer",
        "rainbow_hatchet": "rainbow_hatchet",
        "rainbow_spatula": "rainbow_spatula",
        "rainbow_gauntlets": "rainbow_gauntlets",
        "rainbow_shears": "rainbow_shears",
        "rainbow_brush": "rainbow_brush",
        "rainbow_helmet": "rainbow_helmet",
        "rainbow_plate_legs": "rainbow_plate_legs",
        "rainbow_plate_body": "rainbow_plate_body",
        "rainbow_buckler": "rainbow_buckler",
        "rainbow_chisel": "rainbow_chisel",
        "rainbow_spear": "rainbow_spear",
        "rainbow_bulwark": "rainbow_bulwark",
        "chefs_top": "thread_of_expertise",
        "chefs_bottoms": "thread_of_expertise",
        "magnetic_gloves": "magnet",
        "rough_hood": "rough_hood",
        "rough_bracers": "rough_bracers",
        "rough_chaps": "rough_chaps",
        "rough_tunic": "rough_tunic",
        "verdant_hammer": "verdant_hammer",
        "verdant_hatchet": "verdant_hatchet",
        "verdant_spatula": "verdant_spatula",
        "verdant_gauntlets": "verdant_gauntlets",
        "verdant_shears": "verdant_shears",
        "verdant_brush": "verdant_brush",
        "verdant_helmet": "verdant_helmet",
        "verdant_plate_legs": "verdant_plate_legs",
        "verdant_plate_body": "verdant_plate_body",
        "verdant_buckler": "verdant_buckler",
        "verdant_chisel": "verdant_chisel",
        "verdant_spear": "verdant_spear",
        "verdant_bulwark": "verdant_bulwark",
        "demonic_plate_legs": "demonic_core",
        "demonic_plate_body": "demonic_core",
        "gator_vest": "gator_vest",
        "enchanted_gloves": "chrono_sphere",
        "gobo_boots": "gobo_boots",
        "crafters_top": "thread_of_expertise",
        "crafters_bottoms": "thread_of_expertise",
        "radiant_robe_top": "radiant_robe_top",
        "radiant_robe_bottoms": "radiant_robe_bottoms",
        "radiant_gloves": "radiant_gloves",
        "turtle_shell_legs": "turtle_shell",
        "turtle_shell_body": "turtle_shell",
        "marine_tunic": "marine_scale",
        "marine_chaps": "marine_scale",
        "earrings_of_armor": "earrings_of_armor",
        "ring_of_armor": "ring_of_armor",
        "earrings_of_regeneration": "earrings_of_regeneration",
        "ring_of_regeneration": "ring_of_regeneration",
        "chaotic_flail": "chaotic_chain",
        "spiked_bulwark": "stalactite_shard",
        "crimson_hammer": "crimson_hammer",
        "crimson_hatchet": "crimson_hatchet",
        "crimson_spatula": "crimson_spatula",
        "crimson_gauntlets": "crimson_gauntlets",
        "crimson_shears": "crimson_shears",
        "crimson_brush": "crimson_brush",
        "crimson_helmet": "crimson_helmet",
        "crimson_plate_legs": "crimson_plate_legs",
        "crimson_plate_body": "crimson_plate_body",
        "crimson_buckler": "crimson_buckler",
        "crimson_chisel": "crimson_chisel",
        "crimson_spear": "crimson_spear",
        "crimson_bulwark": "crimson_bulwark",
        "necklace_of_wisdom": "necklace_of_wisdom",
        "shoebill_shoes": "shoebill_feather",
        "watchful_relic": "eye_of_the_watcher",
        "giant_pouch": "mirror_of_protection",
        "colossus_plate_legs": "colossus_core",
        "colossus_plate_body": "colossus_core",
        "regal_sword": "regal_jewel",
        "earrings_of_resistance": "earrings_of_resistance",
        "ring_of_resistance": "ring_of_resistance",
        "furious_spear": "regal_jewel",
        "werewolf_slasher": "werewolf_claw",
        "infernal_battlestaff": "infernal_ember",
        "flaming_robe_top": "flaming_cloth",
        "flaming_robe_bottoms": "flaming_cloth",
        "sundering_crossbow": "sundering_jewel",
        "anchorbound_plate_legs": "damaged_anchor",
        "anchorbound_plate_body": "damaged_anchor",
        "enchanted_cloak": "enchanted_cloak",
        "sighted_bracers": "sighted_bracers",
        "magicians_hat": "magicians_cloth",
        "cheese_hammer": "cheese_hammer",
        "cheese_hatchet": "cheese_hatchet",
        "cheese_spatula": "cheese_spatula",
        "cheese_gauntlets": "cheese_gauntlets",
        "cheese_shears": "cheese_shears",
        "cheese_brush": "cheese_brush",
        "cheese_helmet": "cheese_helmet",
        "cheese_plate_legs": "cheese_plate_legs",
        "cheese_plate_body": "cheese_plate_body",
        "cheese_buckler": "cheese_buckler",
        "cheese_chisel": "cheese_chisel",
        "cheese_spear": "cheese_spear",
        "cheese_bulwark": "cheese_bulwark",
        "maelstrom_plate_legs": "maelstrom_plating",
        "maelstrom_plate_body": "maelstrom_plating",
        "chimerical_quiver": "chimerical_quiver",
        "snake_fang_dirk": "snake_fang",
        "ranger_necklace": "ranger_necklace",
        "burble_hammer": "burble_hammer",
        "burble_hatchet": "burble_hatchet",
        "burble_spatula": "burble_spatula",
        "burble_gauntlets": "burble_gauntlets",
        "burble_shears": "burble_shears",
        "burble_brush": "burble_brush",
        "burble_helmet": "burble_helmet",
        "burble_plate_legs": "burble_plate_legs",
        "burble_plate_body": "burble_plate_body",
        "burble_buckler": "burble_buckler",
        "burble_chisel": "burble_chisel",
        "burble_spear": "burble_spear",
        "burble_bulwark": "burble_bulwark",
        "marksman_bracers": "marksman_brooch",
        "holy_hammer": "holy_hammer",
        "holy_hatchet": "holy_hatchet",
        "holy_spatula": "holy_spatula",
        "holy_gauntlets": "holy_gauntlets",
        "holy_shears": "holy_shears",
        "holy_brush": "holy_brush",
        "holy_helmet": "holy_helmet",
        "holy_plate_legs": "holy_plate_legs",
        "holy_plate_body": "holy_plate_body",
        "holy_buckler": "holy_buckler",
        "holy_chisel": "holy_chisel",
        "holy_spear": "holy_spear",
        "holy_bulwark": "holy_bulwark",
        "griffin_chaps": "griffin_leather",
        "griffin_tunic": "griffin_leather",
        "griffin_bulwark": "griffin_talon",
        "stalactite_spear": "stalactite_shard",
        "chrono_gloves": "chrono_sphere",
        "vision_helmet": "goggles",
        "collectors_boots": "gobo_rag",
        "silk_robe_top": "silk_robe_top",
        "silk_robe_bottoms": "silk_robe_bottoms",
        "necklace_of_speed": "necklace_of_speed",
        "gluttonous_pouch": "mirror_of_protection",
        "revenant_chaps": "revenant_anima",
        "revenant_tunic": "revenant_anima",
        "azure_hammer": "azure_hammer",
        "azure_hatchet": "azure_hatchet",
        "azure_spatula": "azure_spatula",
        "azure_gauntlets": "azure_gauntlets",
        "azure_shears": "azure_shears",
        "azure_brush": "azure_brush",
        "azure_helmet": "azure_helmet",
        "azure_plate_legs": "azure_plate_legs",
        "azure_plate_body": "azure_plate_body",
        "azure_buckler": "azure_buckler",
        "azure_chisel": "azure_chisel",
        "azure_spear": "azure_spear",
        "azure_bulwark": "azure_bulwark",
        "wizard_necklace": "wizard_necklace",
        "philosophers_earrings": "mirror_of_protection",
        "philosophers_ring": "mirror_of_protection",
        "philosophers_necklace": "mirror_of_protection",
        "necklace_of_efficiency": "necklace_of_efficiency",
        "pincer_gloves": "crab_pincer",
        "celestial_hammer": "butter_of_proficiency",
        "celestial_hatchet": "butter_of_proficiency",
        "celestial_spatula": "butter_of_proficiency",
        "celestial_shears": "butter_of_proficiency",
        "celestial_brush": "butter_of_proficiency",
        "celestial_chisel": "butter_of_proficiency",
        "panda_gloves": "panda_fluff",
        "linen_robe_top": "linen_robe_top",
        "linen_robe_bottoms": "linen_robe_bottoms",
        "linen_gloves": "linen_gloves",
        "beast_hood": "beast_hood",
        "beast_bracers": "beast_bracers",
        "beast_chaps": "beast_chaps",
        "beast_tunic": "beast_tunic",
        "sinister_cape": "sinister_cape",
        "tome_of_the_elements": "tome_of_the_elements",
        "luna_robe_top": "luna_wing",
        "luna_robe_bottoms": "luna_wing",
        "fighter_necklace": "fighter_necklace",
        "eye_watch": "eye_of_the_watcher",
        "tome_of_healing": "tome_of_healing",
        "cursed_bow": "cursed_ball",
        "bishops_codex": "bishops_scroll",
        "foragers_top": "thread_of_expertise",
        "foragers_bottoms": "thread_of_expertise",
        "rainbow_mace": "rainbow_mace",
        "rainbow_enhancer": "rainbow_enhancer",
        "rainbow_alembic": "rainbow_alembic",
        "blazing_trident": "kraken_fang",
        "verdant_mace": "verdant_mace",
        "verdant_enhancer": "verdant_enhancer",
        "verdant_alembic": "verdant_alembic",
        "dodocamel_gauntlets": "dodocamel_plume",
        "lumberjacks_top": "thread_of_expertise",
        "lumberjacks_bottoms": "thread_of_expertise",
        "gobo_shooter": "gobo_shooter",
        "gobo_hood": "gobo_hood",
        "gobo_slasher": "gobo_slasher",
        "gobo_bracers": "gobo_bracers",
        "gobo_boomstick": "gobo_boomstick",
        "gobo_chaps": "gobo_chaps",
        "gobo_tunic": "gobo_tunic",
        "gobo_stabber": "gobo_stabber",
        "red_culinary_hat": "red_panda_fluff",
        "redwood_fire_staff": "redwood_fire_staff",
        "redwood_water_staff": "redwood_water_staff",
        "granite_bludgeon": "living_granite",
        "birch_fire_staff": "birch_fire_staff",
        "birch_water_staff": "birch_water_staff",
        "dairyhands_top": "thread_of_expertise",
        "dairyhands_bottoms": "thread_of_expertise",
        "crimson_mace": "crimson_mace",
        "crimson_enhancer": "crimson_enhancer",
        "crimson_alembic": "crimson_alembic",
        "kraken_chaps": "kraken_leather",
        "kraken_tunic": "kraken_leather",
        "rippling_trident": "kraken_fang",
        "alchemists_top": "thread_of_expertise",
        "alchemists_bottoms": "thread_of_expertise",
        "soul_hunter_crossbow": "soul_fragment",
        "jackalope_staff": "jackalope_antler",
        "corsair_helmet": "corsair_crest",
        "wooden_fire_staff": "wooden_fire_staff",
        "wooden_water_staff": "wooden_water_staff",
        "cheese_mace": "cheese_mace",
        "cheese_enhancer": "cheese_enhancer",
        "cheesemakers_top": "thread_of_expertise",
        "cheesemakers_bottoms": "thread_of_expertise",
        "cheese_alembic": "cheese_alembic",
        "reptile_boots": "reptile_boots",
        "fluffy_red_hat": "red_panda_fluff",
        "enhancers_top": "thread_of_expertise",
        "enhancers_bottoms": "thread_of_expertise",
        "burble_mace": "burble_mace",
        "burble_enhancer": "burble_enhancer",
        "burble_alembic": "burble_alembic",
        "arcane_fire_staff": "arcane_fire_staff",
        "arcane_water_staff": "arcane_water_staff",
        "holy_mace": "holy_mace",
        "holy_enhancer": "holy_enhancer",
        "holy_alembic": "holy_alembic",
        "azure_mace": "azure_mace",
        "azure_enhancer": "azure_enhancer",
        "azure_alembic": "azure_alembic",
        "snail_shell_helmet": "snail_shell",
        "vampire_fang_dirk": "vampire_fang",
        "celestial_enhancer": "butter_of_proficiency",
        "celestial_alembic": "butter_of_proficiency",
        "cedar_fire_staff": "cedar_fire_staff",
        "cedar_water_staff": "cedar_water_staff",
        "ginkgo_fire_staff": "ginkgo_fire_staff",
        "ginkgo_water_staff": "ginkgo_water_staff",
        "brewers_top": "thread_of_expertise",
        "brewers_bottoms": "thread_of_expertise",
        "acrobatic_hood": "acrobats_ribbon",
        "blooming_trident": "kraken_fang",
        "purpleheart_fire_staff": "purpleheart_fire_staff",
        "purpleheart_water_staff": "purpleheart_water_staff",
        "master_foraging_charm": "mirror_of_protection",
        "master_brewing_charm": "mirror_of_protection",
        "master_woodcutting_charm": "mirror_of_protection",
        "master_defense_charm": "mirror_of_protection",
        "master_tailoring_charm": "mirror_of_protection",
        "master_attack_charm": "mirror_of_protection",
        "master_milking_charm": "mirror_of_protection",
        "master_melee_charm": "mirror_of_protection",
        "master_alchemy_charm": "mirror_of_protection",
        "master_magic_charm": "mirror_of_protection",
        "master_stamina_charm": "mirror_of_protection",
        "master_cooking_charm": "mirror_of_protection",
        "master_enhancing_charm": "mirror_of_protection",
        "master_ranged_charm": "mirror_of_protection",
        "master_crafting_charm": "mirror_of_protection",
        "master_intelligence_charm": "mirror_of_protection",
        "advanced_foraging_charm": "mirror_of_protection",
        "advanced_brewing_charm": "mirror_of_protection",
        "advanced_woodcutting_charm": "mirror_of_protection",
        "advanced_defense_charm": "mirror_of_protection",
        "advanced_tailoring_charm": "mirror_of_protection",
        "advanced_attack_charm": "mirror_of_protection",
        "advanced_milking_charm": "mirror_of_protection",
        "advanced_melee_charm": "mirror_of_protection",
        "advanced_alchemy_charm": "mirror_of_protection",
        "advanced_magic_charm": "mirror_of_protection",
        "advanced_stamina_charm": "mirror_of_protection",
        "advanced_cooking_charm": "mirror_of_protection",
        "advanced_enhancing_charm": "mirror_of_protection",
        "advanced_task_badge": "advanced_task_badge",
        "advanced_ranged_charm": "mirror_of_protection",
        "advanced_crafting_charm": "mirror_of_protection",
        "advanced_intelligence_charm": "mirror_of_protection",
        "gobo_defender": "gobo_defender",
        "gobo_smasher": "gobo_smasher",
        "redwood_nature_staff": "redwood_nature_staff",
        "birch_nature_staff": "birch_nature_staff",
        "royal_fire_robe_top": "royal_cloth",
        "royal_fire_robe_bottoms": "royal_cloth",
        "royal_water_robe_top": "royal_cloth",
        "royal_water_robe_bottoms": "royal_cloth",
        "basic_foraging_charm": "mirror_of_protection",
        "basic_brewing_charm": "mirror_of_protection",
        "basic_woodcutting_charm": "mirror_of_protection",
        "basic_defense_charm": "mirror_of_protection",
        "basic_tailoring_charm": "mirror_of_protection",
        "basic_attack_charm": "mirror_of_protection",
        "basic_milking_charm": "mirror_of_protection",
        "basic_melee_charm": "mirror_of_protection",
        "basic_alchemy_charm": "mirror_of_protection",
        "basic_magic_charm": "mirror_of_protection",
        "basic_stamina_charm": "mirror_of_protection",
        "basic_cooking_charm": "mirror_of_protection",
        "basic_enhancing_charm": "mirror_of_protection",
        "basic_task_badge": "basic_task_badge",
        "basic_ranged_charm": "mirror_of_protection",
        "basic_crafting_charm": "mirror_of_protection",
        "basic_intelligence_charm": "mirror_of_protection",
        "earrings_of_essence_find": "earrings_of_essence_find",
        "ring_of_essence_find": "ring_of_essence_find",
        "wooden_nature_staff": "wooden_nature_staff",
        "reptile_hood": "reptile_hood",
        "reptile_bracers": "reptile_bracers",
        "reptile_chaps": "reptile_chaps",
        "reptile_tunic": "reptile_tunic",
        "knights_aegis_refined": "knights_aegis_refined",
        "arcane_nature_staff": "arcane_nature_staff",
        "trainee_foraging_charm": "mirror_of_protection",
        "trainee_brewing_charm": "mirror_of_protection",
        "trainee_woodcutting_charm": "mirror_of_protection",
        "trainee_defense_charm": "mirror_of_protection",
        "trainee_tailoring_charm": "mirror_of_protection",
        "trainee_attack_charm": "mirror_of_protection",
        "trainee_milking_charm": "mirror_of_protection",
        "trainee_melee_charm": "mirror_of_protection",
        "trainee_alchemy_charm": "mirror_of_protection",
        "trainee_magic_charm": "mirror_of_protection",
        "trainee_stamina_charm": "mirror_of_protection",
        "trainee_cooking_charm": "mirror_of_protection",
        "trainee_enhancing_charm": "mirror_of_protection",
        "trainee_ranged_charm": "mirror_of_protection",
        "trainee_crafting_charm": "mirror_of_protection",
        "trainee_intelligence_charm": "mirror_of_protection",
        "earrings_of_rare_find": "earrings_of_rare_find",
        "ring_of_rare_find": "ring_of_rare_find",
        "cedar_nature_staff": "cedar_nature_staff",
        "ginkgo_nature_staff": "ginkgo_nature_staff",
        "expert_foraging_charm": "mirror_of_protection",
        "expert_brewing_charm": "mirror_of_protection",
        "expert_woodcutting_charm": "mirror_of_protection",
        "expert_defense_charm": "mirror_of_protection",
        "expert_tailoring_charm": "mirror_of_protection",
        "expert_attack_charm": "mirror_of_protection",
        "expert_milking_charm": "mirror_of_protection",
        "expert_melee_charm": "mirror_of_protection",
        "expert_alchemy_charm": "mirror_of_protection",
        "expert_magic_charm": "mirror_of_protection",
        "expert_stamina_charm": "mirror_of_protection",
        "expert_cooking_charm": "mirror_of_protection",
        "expert_enhancing_charm": "mirror_of_protection",
        "expert_task_badge": "expert_task_badge",
        "expert_ranged_charm": "mirror_of_protection",
        "expert_crafting_charm": "mirror_of_protection",
        "expert_intelligence_charm": "mirror_of_protection",
        "purpleheart_nature_staff": "purpleheart_nature_staff",
        "grandmaster_foraging_charm": "mirror_of_protection",
        "grandmaster_brewing_charm": "mirror_of_protection",
        "grandmaster_woodcutting_charm": "mirror_of_protection",
        "grandmaster_defense_charm": "mirror_of_protection",
        "grandmaster_tailoring_charm": "mirror_of_protection",
        "grandmaster_attack_charm": "mirror_of_protection",
        "grandmaster_milking_charm": "mirror_of_protection",
        "grandmaster_melee_charm": "mirror_of_protection",
        "grandmaster_alchemy_charm": "mirror_of_protection",
        "grandmaster_magic_charm": "mirror_of_protection",
        "grandmaster_stamina_charm": "mirror_of_protection",
        "grandmaster_cooking_charm": "mirror_of_protection",
        "grandmaster_enhancing_charm": "mirror_of_protection",
        "grandmaster_ranged_charm": "mirror_of_protection",
        "grandmaster_crafting_charm": "mirror_of_protection",
        "grandmaster_intelligence_charm": "mirror_of_protection",
        "royal_nature_robe_top": "royal_cloth",
        "royal_nature_robe_bottoms": "royal_cloth",
        "chaotic_flail_refined": "mirror_of_protection",
        "regal_sword_refined": "mirror_of_protection",
        "furious_spear_refined": "mirror_of_protection",
        "sundering_crossbow_refined": "mirror_of_protection",
        "anchorbound_plate_legs_refined": "mirror_of_protection",
        "anchorbound_plate_body_refined": "mirror_of_protection",
        "enchanted_cloak_refined": "mirror_of_protection",
        "magicians_hat_refined": "mirror_of_protection",
        "maelstrom_plate_legs_refined": "mirror_of_protection",
        "maelstrom_plate_body_refined": "mirror_of_protection",
        "chimerical_quiver_refined": "mirror_of_protection",
        "marksman_bracers_refined": "mirror_of_protection",
        "griffin_bulwark_refined": "mirror_of_protection",
        "sinister_cape_refined": "mirror_of_protection",
        "cursed_bow_refined": "mirror_of_protection",
        "bishops_codex_refined": "mirror_of_protection",
        "blazing_trident_refined": "mirror_of_protection",
        "master_cheesesmithing_charm": "mirror_of_protection",
        "dodocamel_gauntlets_refined": "mirror_of_protection",
        "advanced_cheesesmithing_charm": "mirror_of_protection",
        "basic_cheesesmithing_charm": "mirror_of_protection",
        "kraken_chaps_refined": "mirror_of_protection",
        "kraken_tunic_refined": "mirror_of_protection",
        "rippling_trident_refined": "mirror_of_protection",
        "corsair_helmet_refined": "mirror_of_protection",
        "trainee_cheesesmithing_charm": "mirror_of_protection",
        "acrobatic_hood_refined": "mirror_of_protection",
        "blooming_trident_refined": "mirror_of_protection",
        "expert_cheesesmithing_charm": "mirror_of_protection",
        "grandmaster_cheesesmithing_charm": "mirror_of_protection",
        "royal_fire_robe_top_refined": "mirror_of_protection",
        "royal_fire_robe_bottoms_refined": "mirror_of_protection",
        "royal_water_robe_top_refined": "mirror_of_protection",
        "royal_water_robe_bottoms_refined": "mirror_of_protection",
        "royal_nature_robe_top_refined": "mirror_of_protection",
        "royal_nature_robe_bottoms_refined": "mirror_of_protection",
        "gatherer_cape": "gatherer_cape",
        "gatherer_cape_refined": "mirror_of_protection",
        "artificer_cape": "artificer_cape",
        "artificer_cape_refined": "mirror_of_protection",
        "culinary_cape": "culinary_cape",
        "culinary_cape_refined": "mirror_of_protection",
        "chance_cape": "chance_cape",
        "chance_cape_refined": "mirror_of_protection",
        "pathbreaker_boots": "pathbreaker_lodestone",
        "pathbreaker_boots_refined": "mirror_of_protection",
        "pathfinder_boots": "pathfinder_lodestone",
        "pathfinder_boots_refined": "mirror_of_protection",
        "pathseeker_boots": "pathseeker_lodestone",
        "pathseeker_boots_refined": "mirror_of_protection"
    }

    /** 默认强化套装(预置推荐套装,供所有脚本共享) */
    const DEFAULT_ENHANCER_SUITS = [
    {
        "id": 1781352746537,
        "name": "全套生活装备",
        "items": [
            "dairyhands_top",
            "foragers_top",
            "lumberjacks_top",
            "cheesemakers_top",
            "crafters_top",
            "tailors_top",
            "chefs_top",
            "brewers_top",
            "alchemists_top",
            "enhancers_top",
            "dairyhands_bottoms",
            "foragers_bottoms",
            "lumberjacks_bottoms",
            "cheesemakers_bottoms",
            "crafters_bottoms",
            "tailors_bottoms",
            "chefs_bottoms",
            "brewers_bottoms",
            "alchemists_bottoms",
            "enhancers_bottoms",
            "red_culinary_hat",
            "eye_watch",
            "enchanted_gloves",
            "collectors_boots",
            "philosophers_necklace",
            "philosophers_earrings",
            "philosophers_ring"
        ]
    },
    {
        "id": 1781352838649,
        "name": "护符",
        "items": [
            "grandmaster_milking_charm",
            "grandmaster_foraging_charm",
            "grandmaster_woodcutting_charm",
            "grandmaster_cheesesmithing_charm",
            "grandmaster_crafting_charm",
            "grandmaster_tailoring_charm",
            "grandmaster_cooking_charm",
            "grandmaster_brewing_charm",
            "grandmaster_alchemy_charm",
            "grandmaster_enhancing_charm",
            "grandmaster_stamina_charm",
            "grandmaster_intelligence_charm",
            "grandmaster_attack_charm",
            "grandmaster_defense_charm",
            "grandmaster_melee_charm",
            "grandmaster_ranged_charm",
            "grandmaster_magic_charm",
            "master_milking_charm",
            "master_foraging_charm",
            "master_woodcutting_charm",
            "master_cooking_charm",
            "master_brewing_charm",
            "master_alchemy_charm",
            "master_enhancing_charm"
        ]
    },
    {
        "id": 1781360571606,
        "name": "星空装备",
        "items": [
            "celestial_brush",
            "celestial_shears",
            "celestial_hatchet",
            "celestial_hammer",
            "celestial_chisel",
            "celestial_needle",
            "celestial_spatula",
            "celestial_pot",
            "celestial_alembic",
            "celestial_enhancer"
        ]
    },
    {
        "id": 1781355535945,
        "name": "95装备",
        "items": [
            "griffin_bulwark",
            "cursed_bow",
            "furious_spear",
            "regal_sword",
            "chaotic_flail",
            "sundering_crossbow",
            "rippling_trident",
            "blooming_trident",
            "blazing_trident",
            "knights_aegis",
            "manticore_shield",
            "bishops_codex",
            "corsair_helmet",
            "acrobatic_hood",
            "magicians_hat",
            "anchorbound_plate_body",
            "maelstrom_plate_body",
            "kraken_tunic",
            "royal_water_robe_top",
            "royal_nature_robe_top",
            "royal_fire_robe_top",
            "anchorbound_plate_legs",
            "maelstrom_plate_legs",
            "kraken_chaps",
            "royal_water_robe_bottoms",
            "royal_nature_robe_bottoms",
            "royal_fire_robe_bottoms",
            "dodocamel_gauntlets",
            "marksman_bracers",
            "chrono_gloves",
            "pathbreaker_boots",
            "pathfinder_boots",
            "pathseeker_boots"
        ]
    },
    {
        "id": 1781362835430,
        "name": "披风",
        "items": [
            "gatherer_cape",
            "artificer_cape",
            "culinary_cape",
            "chance_cape",
            "enchanted_cloak",
            "sinister_cape"
        ]
    },
    {
        "id": 1781503756795,
        "name": "制作套装",
        "items": [
            "crafters_bottoms",
            "crafters_top",
            "celestial_chisel",
            "grandmaster_crafting_charm",
            "guzzling_pouch",
            "philosophers_necklace",
            "eye_watch"
        ]
    }
];

    /** 默认配装存档(空对象) */
    const DEFAULT_ENHANCER_LOADOUTS = {
        "26868": 14963,
        "26870": 14966,
        "26879": 14980,
        "26938": 15084,
        "26939": 15083,
        "26940": 16772,
        "27186": 15482,
        "28597": 19265,
        "29772": 25691,
        "29773": 25692,
        "29774": 25693,
        "29775": 25724,
        "29776": 25725,
        "29777": 25726,
        "29778": 25714,
        "29779": 25716,
        "29780": 25717,
        "29781": 25656,
        "29782": 25657,
        "29783": 25658
    };

    // 内存缓存
    let g_enhancerDict = {};
    let g_enhancerMap = {};
    let g_enhancerLoadouts = {};

    // 初始化强化数据(同步构建基础数据)
    function _initEnhancerData() {
        g_enhancerDict = _buildDefaultEnhancerDict();
        g_enhancerMap = DEFAULT_ENHANCER_MAP;
        g_enhancerLoadouts = DEFAULT_ENHANCER_LOADOUTS;
        // 清理旧的 localStorage 数据
        localStorage.removeItem(ENHANCER_KEYS.DICT);
        localStorage.removeItem(ENHANCER_KEYS.MAP);
        localStorage.removeItem(ENHANCER_KEYS.LOADOUTS);
    }
    _initEnhancerData();

    // ==========================================
    // 暴露全局 API (Expose to window)
    // ==========================================
    window.tmData = {
        version: '1.0.0',

        // 汉化
        getChineseName: getChineseName,
        getItemNameMap: () => ITEM_NAME_MAP,

        // 分类数据
        WIKI_CATEGORIES: WIKI_CATEGORIES,
        FLAT_WIKI_GROUPS: FLAT_WIKI_GROUPS,

        // 常量
        SPRITE_URL: SPRITE_URL,

        // 工具函数
        /**
         * 更新汉化数据(仅更新内存,不写入 localStorage)
         * 永久修改请直接编辑本脚本顶部的 CN_DATA_STR
         * @param {string} str - 汉化映射字符串
         */
        updateCn: window.tmUpdateCn,

        /**
         * 判断物品属于哪个分类
         * @param {string} itemShortId - 物品短ID
         * @returns {string|null} 分类名,找不到返回 null
         */
        getItemCategory: function (itemShortId) {
            for (const [catName, items] of Object.entries(WIKI_CATEGORIES)) {
                if (items.includes(itemShortId)) return catName;
            }
            return null;
        },

        // ==========================================
        // 强化助手共享数据 API
        // ==========================================

        /** 获取强化助手装备汉化字典 */
        getEnhancerDict: () => g_enhancerDict,

        /** 获取强化助手装备保护映射 */
        getEnhancerMap: () => g_enhancerMap,

        /** 获取强化配装存档 */
        getEnhancerLoadouts: () => g_enhancerLoadouts,

        /** 保存强化助手装备汉化字典 */
        saveEnhancerDict: function (data) {
            g_enhancerDict = data || {};
            try { localStorage.setItem(ENHANCER_KEYS.DICT, JSON.stringify(g_enhancerDict)); } catch (e) { }
        },

        /** 保存强化助手装备保护映射 */
        saveEnhancerMap: function (data) {
            g_enhancerMap = data || {};
            try { localStorage.setItem(ENHANCER_KEYS.MAP, JSON.stringify(g_enhancerMap)); } catch (e) { }
        },

        /** 保存强化配装存档 */
        saveEnhancerLoadouts: function (data) {
            g_enhancerLoadouts = data || {};
            try { localStorage.setItem(ENHANCER_KEYS.LOADOUTS, JSON.stringify(g_enhancerLoadouts)); } catch (e) { }
        },

        /** 获取默认强化套装(数据中心预置的共享套装) */
        getDefaultEnhancerSuits: () => DEFAULT_ENHANCER_SUITS,

        // ==========================================
        // 商店数据 API
        // ==========================================

        /** 获取商店物品列表 */
        getShopItems: () => SHOP_ITEMS.slice(),

        /** 获取物品商店价格(数字,单位金币) */
        getShopPrice: function (itemId) {
            const shortId = (itemId || '').split('/').pop();
            return SHOP_PRICE_MAP[shortId] || 0;
        },

        /**
         * 更新商店数据(内存 + localStorage持久化)
         * @param {Array} items - 商店物品数组,格式 [{id, name, price}, ...]
         */
        updateShopData: function (items) {
            if (!Array.isArray(items)) return;
            SHOP_ITEMS = items;
            _buildShopPriceMap();
            try { localStorage.setItem('tm_milky_shop_data_v2', JSON.stringify(SHOP_ITEMS)); } catch(e) {}
            window.dispatchEvent(new CustomEvent('tmData:shopUpdated'));
            console.log('[数据中心] 商店数据已更新,共' + items.length + '条');
        }
    };

    /**
     * 异步初始化数据中心:等待官方汉化拉取完成后再触发ready事件
     */
    async function initDataCenter() {
        // 确保脚本DOM加载完成再执行fetch
        if (document.readyState === 'loading') {
            await new Promise(resolve => document.addEventListener('DOMContentLoaded', resolve));
        }
        // 拉取官方汉化(失败则自动回退到本地空数据/normalize)
        await fetchOfficialItemNames();
        // 强化字典可能已经在fetchOfficialItemNames里重建过,这里广播就绪事件
        window.dispatchEvent(new CustomEvent('tmData:ready'));
        console.log('[数据中心] 初始化完成,已发送tmData:ready事件');
    }
    // 启动异步初始化
    initDataCenter();
    
    // 监听汉化更新事件,自动重新构建强化装备字典并广播更新
    window.addEventListener('tmData:cnUpdated', () => {
        normalizeItemNameMap();
        g_enhancerDict = _buildDefaultEnhancerDict();
        window.dispatchEvent(new CustomEvent('tmData:ready'));
    });

})();