MediaWiki

Common.js:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
 
(未显示同一用户的33个中间版本)
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */


/* 切换标签 */
// 等待 mw 对象加载完成
(function() {
mw.loader.using(['mediawiki.util'], function() {
    'use strict';
      
      
     function initTabSwitcher() {
    // 动态加载 PIXI.js
         var tabContainers = document.querySelectorAll('.resp-tabs');
     function loadScript(url) {
       
         return new Promise(function(resolve, reject) {
        tabContainers.forEach(function(container) {
             var script = document.createElement('script');
             var tabButtons = container.querySelectorAll('.czn-list-style');
             script.src = url;
             if (tabButtons.length === 0) return;
             script.onload = resolve;
              
             script.onerror = reject;
            var tabContents = container.querySelectorAll('.resp-tab-content');
             document.head.appendChild(script);
           
            // 初始化
            tabButtons.forEach(function(button, index) {
                button.classList.toggle('active', index === 0);
             });
           
            if (tabContents.length > 0) {
                tabContents.forEach(function(content, index) {
                    content.style.display = index === 0 ? 'block' : 'none';
                });
             }
           
            // 点击事件
            tabButtons.forEach(function(button, index) {
                button.addEventListener('click', function(e) {
                    e.preventDefault();
                   
                    // 更新标签状态
                    tabButtons.forEach(function(btn, i) {
                        btn.classList.toggle('active', i === index);
                    });
                   
                    // 切换内容
                    if (tabContents.length > 0) {
                        tabContents.forEach(function(content, i) {
                            content.style.display = i === index ? 'block' : 'none';
                        });
                    }
                });
            });
         });
         });
     }
     }
      
      
     // 初始化
     // 按顺序加载库
     if (document.readyState === 'loading') {
     loadScript('https://cdn.jsdelivr.net/npm/pixi.js@5.3.12/dist/pixi.min.js')
         document.addEventListener('DOMContentLoaded', initTabSwitcher);
         .then(function() {
    } else {
            return loadScript('https://cdn.jsdelivr.net/npm/pixi-spine@3.0.12/dist/pixi-spine.js');
        initTabSwitcher();
         })
    }
         .then(function() {
})();
             console.log('Spine libraries loaded successfully');
 
             initSpinePlayers();
/* 战斗员筛选 */
        })
$(function() {
        .catch(function(error) {
    // 初始化筛选系统
             console.error('Failed to load Spine libraries:', error);
    function initFilterSystem() {
         // 清理数据并设置属性
         $('.战斗员卡片').each(function() {
             var $card = $(this);
           
            var rarity = ($card.attr('data-rarity') || '').trim();
             var profession = ($card.attr('data-profession') || '').trim();
            var attribute = ($card.attr('data-attribute') || '').trim();
           
             $card.attr({
                'data-rarity': rarity,
                'data-profession': profession,
                'data-attribute': attribute
            });
         });
         });
   
    function initSpinePlayers() {
        var containers = document.querySelectorAll('.spine-player-container');
          
          
         // 存储当前筛选状态
         if (containers.length === 0) {
         var activeFilters = {};
            console.log('No spine containers found');
            return;
         }
          
          
         // 筛选按钮点击事件
         containers.forEach(function(container) {
        $('.filter-button').off('click').on('click', function(e) {
            var skelUrl = container.getAttribute('data-skel');
             e.preventDefault();
            var atlasUrl = container.getAttribute('data-atlas');
            var animationName = container.getAttribute('data-animation') || 'idle';
             var skinName = container.getAttribute('data-skin') || 'default';
              
              
             var $button = $(this);
             if (!skelUrl || !atlasUrl) {
            var group = String($button.data('filter-group'));
                 console.error('Missing skel or atlas URL');
            var value = String($button.data('filter-value')).trim();
                 return;
           
            // 切换按钮状态
            if (group === '0' && value === '0') {
                // 查看全部按钮
                $('.filter-button').removeClass('active');
                $button.addClass('active');
                activeFilters = {};
            } else {
                // 其他筛选按钮
                $('.filter-button[data-filter-group="0"]').removeClass('active');
               
                // 同组内只能选择一个
                $('.filter-button[data-filter-group="' + group + '"]').removeClass('active');
               
                if (activeFilters[group] === value) {
                    // 如果点击已激活的按钮,则取消选择
                    delete activeFilters[group];
                    $button.removeClass('active');
                 } else {
                    // 激活新的筛选
                    $button.addClass('active');
                    activeFilters[group] = value;
                }
                  
                // 如果没有任何筛选项,激活"查看全部"
                if (Object.keys(activeFilters).length === 0) {
                    $('.filter-button[data-filter-group="0"][data-filter-value="0"]').addClass('active');
                }
             }
             }
              
              
             // 应用筛选
             // 创建 PIXI 应用
             applyFilters();
             var app = new PIXI.Application({
        });
                width: container.clientWidth || 800,
       
                height: container.clientHeight || 600,
        // 应用筛选函数
                backgroundColor: 0x2c3e50,
        function applyFilters() {
                transparent: false
            $('.战斗员卡片').each(function() {
                var $card = $(this);
                var shouldShow = true;
               
                // 检查每个激活的筛选条件
                for (var group in activeFilters) {
                    var filterValue = String(activeFilters[group]).trim();
                    var cardValue = '';
                   
                    // 根据组号获取对应的卡片属性
                    switch(group) {
                        case '1': // 稀有度
                            cardValue = String($card.attr('data-rarity') || '').trim();
                            break;
                        case '2': // 职业
                            cardValue = String($card.attr('data-profession') || '').trim();
                            break;
                        case '3': // 属性
                            cardValue = String($card.attr('data-attribute') || '').trim();
                            break;
                        default:
                            cardValue = String($card.attr('data-filter-' + group) || '').trim();
                    }
                   
                    if (cardValue !== filterValue) {
                        shouldShow = false;
                        break;
                    }
                }
               
                // 显示或隐藏卡片
                if (shouldShow) {
                    $card.fadeIn(200);
                } else {
                    $card.fadeOut(200);
                }
             });
             });
              
              
             // 更新显示数量
             container.innerHTML = '';
            updateCount();
             container.appendChild(app.view);
        }
       
        // 更新显示数量
        function updateCount() {
            var visibleCount = $('.战斗员卡片:visible').length;
             var totalCount = $('.战斗员卡片').length;
              
              
             if ($('#filter-count').length === 0) {
             // 加载 Spine 资源
                $('.filter-container').prepend('<div id="filter-count"></div>');
            app.loader
            }
                .add('spineData', skelUrl)
           
                .load(function(loader, resources) {
            $('#filter-count').text('显示 ' + visibleCount + ' / ' + totalCount + ' 个战斗员');
                    try {
        }
                        var animation = new PIXI.spine.Spine(resources.spineData.spineData);
       
                       
        // 初始化筛选按钮的data属性(清理空格)
                        // 设置位置和缩放
        $('.filter-button').each(function() {
                        animation.x = app.screen.width / 2;
            var $button = $(this);
                        animation.y = app.screen.height / 2;
            var value = String($button.data('filter-value') || '').trim();
                        animation.scale.set(0.5);
            $button.attr('data-filter-value', value);
                       
                        // 播放动画
                        if (animation.state.hasAnimation(animationName)) {
                            animation.state.setAnimation(0, animationName, true);
                        }
                       
                        app.stage.addChild(animation);
                        console.log('Spine animation loaded successfully');
                    } catch(e) {
                        console.error('Error creating spine animation:', e);
                    }
                });
         });
         });
       
        // 初始化时激活"查看全部"按钮
        $('.filter-button[data-filter-group="0"][data-filter-value="0"]').addClass('active');
        updateCount();
     }
     }
   
    // 等待页面加载完成
    var checkInterval = setInterval(function() {
        if ($('.战斗员卡片').length > 0 && $('.filter-button').length > 0) {
            clearInterval(checkInterval);
            initFilterSystem();
        }
    }, 500);
   
    // 10秒后停止检查
    setTimeout(function() {
        clearInterval(checkInterval);
    }, 10000);
});
});


/* 卡牌 */
/* 卡牌 */
(function() {
(function () {
     // 防止重复初始化
     'use strict';
    if (window.cardSystemInitialized) return;
 
    window.cardSystemInitialized = true;
     var initialized = false;
   
 
    // 缓存DOM元素
     function show(el) {
     var overlayCache = null;
        if (el) el.style.display = 'flex';
    var containerCache = null;
     }
      
     function hide(el) {
    // 保存当前卡牌信息,用于返回
        if (el) el.style.display = 'none';
    var currentCardInfo = null;
     }
      
 
     // 添加历史栈来记录浏览历史
     function resetModalView(modal) {
    var viewHistory = [];
         var originalView = modal.querySelector('.original-card-view');
      
         var inspirationView = modal.querySelector('.inspiration-view');
    // 创建遮罩层和容器
         var godView = modal.querySelector('.god-inspiration-view');
     function createCardOverlay() {
         var subcardsView = modal.querySelector('.subcards-view');
         if (overlayCache && containerCache) {
         var nestedSubcardsViews = modal.querySelectorAll('.nested-subcards-view');
            return { overlay: overlayCache, container: containerCache };
         var inspirationNestedViews = modal.querySelectorAll('.inspiration-subcards-view');
        }
         var inspirationDeeperNestedViews = modal.querySelectorAll('.inspiration-nested-subcards-view');
       
 
        // 创建遮罩
         if (originalView) show(originalView);
         var overlay = document.createElement('div');
         if (inspirationView) hide(inspirationView);
         overlay.id = 'card-overlay';
         if (godView) hide(godView);
         overlay.style.cssText = 'display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 9999; overflow-y: auto;';
         if (subcardsView) hide(subcardsView);
       
 
        // 创建容器
         nestedSubcardsViews.forEach(hide);
         var container = document.createElement('div');
        inspirationNestedViews.forEach(hide);
         container.id = 'card-display-container';
        inspirationDeeperNestedViews.forEach(hide);
         container.style.cssText = 'position: relative; min-height: 100vh; padding: 40px 20px; display: flex; align-items: center; justify-content: center;';
    }
         overlay.appendChild(container);
 
         document.body.appendChild(overlay);
    function closeModal(modal) {
          
         modal.style.display = 'none';
         // 点击遮罩关闭
         document.body.style.overflow = 'auto';
         overlay.addEventListener('click', function(e) {
         resetModalView(modal);
            if (e.target === overlay) {
                closeCardDisplay();
            }
        });
          
        overlayCache = overlay;
         containerCache = container;
          
        return { overlay: overlay, container: container };
     }
     }
   
 
    // 创建关闭按钮
     function openModalFromCard(cardWrapper) {
     function createCloseButton() {
         var cardId = cardWrapper.getAttribute('data-card-id');
         var closeBtn = document.createElement('div');
         if (!cardId) return;
         closeBtn.style.cssText = 'position: fixed; top: 20px; right: 20px; width: 40px; height: 40px; background: rgba(255,255,255,0.1); border: 2px solid white; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 10001; transition: all 0.3s;';
         var modal = document.getElementById(cardId + '-modal');
         closeBtn.innerHTML = '<span style="color: white; font-size: 24px; font-weight: bold; line-height: 1;">×</span>';
         if (!modal) return;
         closeBtn.onmouseover = function() {
        resetModalView(modal);
            this.style.background = 'rgba(255,255,255,0.2)';  
        modal.style.display = 'block';
            this.style.transform = 'scale(1.1)';
         document.body.style.overflow = 'hidden';
         };
        closeBtn.onmouseout = function() {
            this.style.background = 'rgba(255,255,255,0.1)';
            this.style.transform = 'scale(1)';
        };
        closeBtn.onclick = function() {
            closeCardDisplay();
        };
        return closeBtn;
     }
     }
   
 
    // 关闭卡牌展示
     function handleBackToCard(button) {
     function closeCardDisplay() {
         var modal = button.closest('.card-modal');
         var overlay = document.getElementById('card-overlay');
         if (modal) {
         if (overlay) {
             resetModalView(modal);
             overlay.style.display = 'none';
            var container = overlay.querySelector('#card-display-container');
            if (container) {
                container.innerHTML = '';
            }
         }
         }
        currentCardInfo = null;
        viewHistory = []; // 清空历史栈
     }
     }
   
 
    // 返回上一层
     function handleBackToSubcards(button) {
     function goBack() {
         var modal = button.closest('.card-modal');
         if (viewHistory.length > 1) {
        if (!modal) return;
            // 移除当前视图
        var nestedView = button.closest('.nested-subcards-view');
            viewHistory.pop();
        var subcardsView = modal.querySelector('.subcards-view');
            // 获取上一个视图
         if (nestedView && subcardsView) {
            var previousView = viewHistory.pop();
             hide(nestedView);
            // 根据视图类型重新渲染
             show(subcardsView);
            if (previousView.type === 'enlarged') {
                showEnlargedCard(previousView.data.element, false); // false 表示不添加到历史
            } else if (previousView.type === 'derivedCards') {
                showAllDerivedCards(previousView.data.character, previousView.data.derivedCardsList, false);
            } else if (previousView.type === 'variantCards') {
                showVariantCards(previousView.data.character, previousView.data.cardName, previousView.data.variantType, false);
            }
         } else if (viewHistory.length === 1) {
             // 只剩一层,关闭弹窗
             closeCardDisplay();
         }
         }
     }
     }
      
 
     // 缓存API调用结果
     function handleInspirationClick(button) {
     var apiCache = {};
        var modal = button.closest('.card-modal');
      
        if (!modal) return;
    // 获取卡牌HTML
        var originalView = modal.querySelector('.original-card-view');
     function fetchCardHTML(character, cardName, deckType, callback) {
        var inspirationView = modal.querySelector('.inspiration-view');
         var cacheKey = character + '|' + cardName + '|' + (deckType || '');
        if (!originalView || !inspirationView) return;
          
        hide(originalView);
         // 检查缓存
        show(inspirationView);
         if (apiCache[cacheKey]) {
     }
             callback(apiCache[cacheKey]);
 
             return;
     function handleGodInspirationClick(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var originalView = modal.querySelector('.original-card-view');
        var godView = modal.querySelector('.god-inspiration-view');
        if (!originalView || !godView) return;
        hide(originalView);
        show(godView);
    }
 
    function handleSubcardsClick(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var originalView = modal.querySelector('.original-card-view');
        var subcardsView = modal.querySelector('.subcards-view');
        if (!originalView || !subcardsView) return;
        hide(originalView);
        show(subcardsView);
     }
 
     function handleViewNestedSubcardsClick(button) {
         var modal = button.closest('.card-modal');
        if (!modal) return;
        var subcardIndex = button.getAttribute('data-subcard-index');
        if (!subcardIndex) return;
        var subcardsView = modal.querySelector('.subcards-view');
        var nestedView = modal.querySelector('.nested-subcards-view[data-subcard-index="' + subcardIndex + '"]');
        if (!subcardsView || !nestedView) return;
        hide(subcardsView);
        show(nestedView);
    }
 
    function handleInspirationSubcardsClick(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var idx = button.getAttribute('data-variant-index');
        if (!idx) return;
        var inspirationView = modal.querySelector('.inspiration-view');
        var nestedView = modal.querySelector('.inspiration-subcards-view[data-variant-index="' + idx + '"]');
        if (!inspirationView || !nestedView) return;
        hide(inspirationView);
        show(nestedView);
    }
 
    function handleBackToInspiration(button) {
        var modal = button.closest('.card-modal');
         if (!modal) return;
        var nestedView = button.closest('.inspiration-subcards-view');
         var inspirationView = modal.querySelector('.inspiration-view');
         if (nestedView && inspirationView) {
             hide(nestedView);
             show(inspirationView);
         }
         }
       
        var api = new mw.Api();
        var wikitext = '{{#invoke:卡牌|main|' + character + '|' + cardName + '|' + (deckType || '') + '}}';
       
        api.parse(wikitext).done(function(html) {
            apiCache[cacheKey] = html;
            callback(html);
        }).fail(function() {
            callback('<div style="color: white;">加载失败</div>');
        });
     }
     }
      
 
     // 放大显示卡牌 - 添加 addToHistory 参数
     function handleViewInspirationNestedSubcardsClick(button) {
     function showEnlargedCard(cardElement, addToHistory) {
        var modal = button.closest('.card-modal');
         if (addToHistory !== false) {
        if (!modal) return;
             addToHistory = true; // 默认添加到历史
        var vIdx = button.getAttribute('data-variant-index');
        var sIdx = button.getAttribute('data-subcard-index');
        if (!vIdx || !sIdx) return;
        var subcardsView = modal.querySelector('.inspiration-subcards-view[data-variant-index="' + vIdx + '"]');
        var deeperView = modal.querySelector('.inspiration-nested-subcards-view[data-variant-index="' + vIdx + '"][data-subcard-index="' + sIdx + '"]');
        if (!subcardsView || !deeperView) return;
        hide(subcardsView);
        show(deeperView);
     }
 
     function handleBackToInspirationSubcards(button) {
        var modal = button.closest('.card-modal');
         if (!modal) return;
        var deeperView = button.closest('.inspiration-nested-subcards-view');
        var vIdx = button.getAttribute('data-variant-index');
        var subcardsView = modal.querySelector('.inspiration-subcards-view[data-variant-index="' + vIdx + '"]');
        if (deeperView && subcardsView) {
             hide(deeperView);
            show(subcardsView);
         }
         }
          
    }
        var elements = createCardOverlay();
 
        var container = elements.container;
    function onKeydown(event) {
        var cardName = cardElement.dataset.cardName;
         if (event.key === 'Escape' || event.keyCode === 27) {
        var character = cardElement.dataset.character;
            var modals = document.querySelectorAll('.card-modal');
        var deckType = cardElement.dataset.deckType;
            modals.forEach(function (modal) {
        var derivedCards = cardElement.dataset.derivedCards;
                if (modal.style.display === 'block') {
        var hasMechanism = cardElement.dataset.hasMechanism === 'true';
                    var inspirationView = modal.querySelector('.inspiration-view');
     
                    var godView = modal.querySelector('.god-inspiration-view');
        // 保存当前卡牌信息
                    var subcardsView = modal.querySelector('.subcards-view');
        currentCardInfo = {
                    var nestedSubcardsViews = modal.querySelectorAll('.nested-subcards-view');
            element: cardElement,
                    var inspirationNestedViews = modal.querySelectorAll('.inspiration-subcards-view');
            cardName: cardName,
                    var inspirationDeeperNestedViews = modal.querySelectorAll('.inspiration-nested-subcards-view');
            character: character,
 
            deckType: deckType,
                    var inNestedView = false;
            derivedCards: derivedCards
                    nestedSubcardsViews.forEach(function (view) {
        };
                        if (view.style.display !== 'none') {
       
                            inNestedView = true;
        // 添加到历史栈
                            hide(view);
        if (addToHistory) {
                            if (subcardsView) show(subcardsView);
            viewHistory.push({
                        }
                type: 'enlarged',
                    });
                data: {
 
                    element: cardElement,
                    var inInspirationNested = false;
                    cardName: cardName,
                    inspirationNestedViews.forEach(function (view) {
                    character: character,
                        if (view.style.display !== 'none') {
                    deckType: deckType,
                            inInspirationNested = true;
                     derivedCards: derivedCards
                            hide(view);
                            if (inspirationView) show(inspirationView);
                        }
                    });
 
                    var inInspirationDeeperNested = false;
                    inspirationDeeperNestedViews.forEach(function (view) {
                        if (view.style.display !== 'none') {
                            inInspirationDeeperNested = true;
                            var vIdx = view.getAttribute('data-variant-index');
                            hide(view);
                            var parentSubcardsView = modal.querySelector('.inspiration-subcards-view[data-variant-index="' + vIdx + '"]');
                            if (parentSubcardsView) show(parentSubcardsView);
                        }
                    });
 
                    if (!inNestedView && !inInspirationNested && !inInspirationDeeperNested) {
                        if ((inspirationView && inspirationView.style.display !== 'none') ||
                            (subcardsView && subcardsView.style.display !== 'none') ||
                            (godView && godView.style.display !== 'none')) {
                            resetModalView(modal);
                        } else {
                            closeModal(modal);
                        }
                     }
                 }
                 }
             });
             });
         }
         }
      
     }
         // 重置容器样式
 
         container.style.cssText = 'position: relative; min-height: 100vh; padding: 40px 20px; display: flex; align-items: center; justify-content: center;';
    function onDocumentClick(e) {
   
         // 打开模态:点击卡片缩略图区域
         // 创建内容包装器
         var cardWrapper = e.target.closest('.card-small-wrapper');
        var contentWrapper = document.createElement('div');
         if (cardWrapper) {
        contentWrapper.style.cssText = 'display: flex; align-items: flex-start; gap: 0px; position: relative;';
            e.preventDefault();
   
            e.stopPropagation();
         // 处理衍生卡牌(左侧)
            openModalFromCard(cardWrapper);
         if (derivedCards && derivedCards.trim() !== '') {
            return;
             var leftContainer = document.createElement('div');
        }
             leftContainer.style.cssText = 'display: flex; flex-direction: column; gap: 0px; align-items: center;';
 
          
         // 变体/衍生/返回/关闭
            var derivedCardsList = derivedCards.split('');
         if (e.target.classList.contains('inspiration-button')) {
       
             e.stopPropagation();
             var derivedCardWrapper = document.createElement('div');
             handleInspirationClick(e.target);
             derivedCardWrapper.style.cssText = 'width: 252px; height: 345px; display: flex; align-items: center; justify-content: center;';
            return;
          
         }
            var firstDerivedCard = document.createElement('div');
        if (e.target.classList.contains('god-inspiration-button')) {
             firstDerivedCard.id = 'derived-cards-display';
             e.stopPropagation();
             firstDerivedCard.style.cssText = 'transform: scale(1.5); transform-origin: center center;';
             handleGodInspirationClick(e.target);
          
            return;
            fetchCardHTML(character, derivedCardsList[0].trim(), '', function(html) {
         }
                firstDerivedCard.innerHTML = html;
        if (e.target.classList.contains('subcards-button')) {
                var cards = firstDerivedCard.querySelectorAll('.game-card');
             e.stopPropagation();
                cards.forEach(function(card) {
             handleSubcardsClick(e.target);
                    card.style.cursor = 'default';
            return;
                    card.onclick = function(e) {
         }
                        e.stopPropagation();
        if (e.target.classList.contains('view-nested-subcards-button')) {
                        e.preventDefault();
            e.stopPropagation();
                    };
            handleViewNestedSubcardsClick(e.target);
                });
            return;
             });
        }
       
        if (e.target.classList.contains('back-to-card-button')) {
             derivedCardWrapper.appendChild(firstDerivedCard);
            e.stopPropagation();
             leftContainer.appendChild(derivedCardWrapper);
            handleBackToCard(e.target);
          
            return;
            if (derivedCardsList.length > 1) {
        }
                var viewAllBtn = document.createElement('div');
        if (e.target.classList.contains('back-to-subcards-button')) {
                viewAllBtn.style.cssText = 'padding: 10px 20px; background: linear-gradient(135deg, #4a90e2, #357abd); color: white; border-radius: 6px; cursor: pointer; white-space: nowrap; font-weight: bold; box-shadow: 0 2px 8px rgba(0,0,0,0.3); transition: transform 0.2s; margin-top: 0px;';
             e.stopPropagation();
                viewAllBtn.textContent = '查看所有衍生卡牌';
             handleBackToSubcards(e.target);
                viewAllBtn.onmouseover = function() { this.style.transform = 'scale(1.05)'; };
             return;
                viewAllBtn.onmouseout = function() { this.style.transform = 'scale(1)'; };
         }
                viewAllBtn.onclick = function() {
        if (e.target.classList.contains('view-insp-subcards-button')) {
                    showAllDerivedCards(character, derivedCardsList);
            e.stopPropagation();
                };
            handleInspirationSubcardsClick(e.target);
                leftContainer.appendChild(viewAllBtn);
            return;
             }
        }
       
        if (e.target.classList.contains('back-to-inspiration-button')) {
             contentWrapper.appendChild(leftContainer);
            e.stopPropagation();
            handleBackToInspiration(e.target);
            return;
        }
        if (e.target.classList.contains('view-insp-nested-subcards-button')) {
            e.stopPropagation();
            handleViewInspirationNestedSubcardsClick(e.target);
            return;
        }
        if (e.target.classList.contains('back-to-insp-subcards-button')) {
             e.stopPropagation();
             handleBackToInspirationSubcards(e.target);
            return;
         }
         }
   
 
         // 创建中间主卡牌区域
         // 关闭按钮
         var centerContainer = document.createElement('div');
         var closeBtn = e.target.classList.contains('modal-close-button')
        centerContainer.style.cssText = 'display: flex; flex-direction: column; align-items: center; gap: 0px;';
            ? e.target
   
            : (e.target.parentElement && e.target.parentElement.classList.contains('modal-close-button') ? e.target.parentElement : null);
        var mainCardContainer = document.createElement('div');
 
        mainCardContainer.style.cssText = 'width: 336px; height: 460px; display: flex; align-items: center; justify-content: center; position: relative;';
         if (closeBtn) {
   
            var modal = closeBtn.closest('.card-modal');
        var cardInner = document.createElement('div');
             if (modal) closeModal(modal);
        cardInner.style.cssText = 'transform: scale(2); position: relative;';
   
        var enlargedCard = cardElement.cloneNode(true);
        enlargedCard.style.width = '168px';
        enlargedCard.style.height = '230px';
        enlargedCard.style.cursor = 'default';
        enlargedCard.style.position = 'relative';
        enlargedCard.style.display = 'block';
        enlargedCard.onclick = null;
   
        cardInner.appendChild(enlargedCard);
        mainCardContainer.appendChild(cardInner);
        centerContainer.appendChild(mainCardContainer);
   
        // 创建按钮容器
        var buttonsContainer = document.createElement('div');
        buttonsContainer.style.cssText = 'display: flex; gap: 15px; white-space: nowrap;';
   
        checkCardVariants(character, cardName, function(variants) {
            if (variants.lingguang) {
                var lingguangBtn = document.createElement('div');
                lingguangBtn.style.cssText = 'padding: 10px 30px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 6px; cursor: pointer; font-weight: bold; box-shadow: 0 2px 8px rgba(0,0,0,0.3); transition: transform 0.2s; white-space: nowrap; min-width: 120px; text-align: center;';
                lingguangBtn.textContent = '灵光一闪';
                lingguangBtn.onmouseover = function() { this.style.transform = 'scale(1.05)'; };
                lingguangBtn.onmouseout = function() { this.style.transform = 'scale(1)'; };
                lingguangBtn.onclick = function() {
                    showVariantCards(character, cardName, '灵光一闪');
                };
                buttonsContainer.appendChild(lingguangBtn);
            }
          
            if (variants.shenguang) {
                var shenguangBtn = document.createElement('div');
                shenguangBtn.style.cssText = 'padding: 10px 30px; background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); color: white; border-radius: 6px; cursor: pointer; font-weight: bold; box-shadow: 0 2px 8px rgba(0,0,0,0.3); transition: transform 0.2s; white-space: nowrap; min-width: 120px; text-align: center;';
                shenguangBtn.textContent = '神之一闪';
                shenguangBtn.onmouseover = function() { this.style.transform = 'scale(1.05)'; };
                shenguangBtn.onmouseout = function() { this.style.transform = 'scale(1)'; };
                shenguangBtn.onclick = function() {
                    showVariantCards(character, cardName, '神之一闪');
                };
                buttonsContainer.appendChild(shenguangBtn);
            }
       
            if (buttonsContainer.children.length > 0) {
                centerContainer.appendChild(buttonsContainer);
            }
        });
   
        contentWrapper.appendChild(centerContainer);
   
        // 添加右侧机制说明
        if (hasMechanism) {
            var mechanismContainer = cardElement.nextElementSibling;
             if (mechanismContainer && mechanismContainer.classList.contains('mechanism-container')) {
                var mechanismDisplay = document.createElement('div');
                mechanismDisplay.style.cssText = 'display: flex; flex-direction: column; gap: 0px; max-width: 320px; min-width: 280px;';
                mechanismDisplay.innerHTML = mechanismContainer.innerHTML;
                mechanismDisplay.style.display = 'flex';
           
                contentWrapper.appendChild(mechanismDisplay);
            }
         }
         }
   
        container.innerHTML = '';
        container.appendChild(contentWrapper);
        container.appendChild(createCloseButton());
   
        elements.overlay.style.display = 'block';
     }
     }


     // 显示所有衍生卡牌 - 添加 addToHistory 参数
     function init() {
     function showAllDerivedCards(character, derivedCardsList, addToHistory) {
        if (initialized) return;
         if (addToHistory !== false) {
        initialized = true;
             addToHistory = true;
 
        document.addEventListener('click', onDocumentClick);
        document.addEventListener('keydown', onKeydown);
    }
 
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
 
    if (typeof mw !== 'undefined' && mw.hook) {
        // 页面增量渲染时确保已初始化(事件委托只需一次)
        mw.hook('wikipage.content').add(function () { init(); });
    }
})();
 
// 卡牌悬停显示功能
(function () {
    'use strict';
 
    var hoverTimeout;
 
     function showCardPopup(linkElement) {
        // 清除之前的超时
         if (hoverTimeout) {
            clearTimeout(hoverTimeout);
        }
 
        // 检查是否已有弹出框
        var existingPopup = linkElement.querySelector('.card-hover-popup');
        if (existingPopup) {
            return;
        }
 
        // 查找紧邻的隐藏数据容器
        var dataContainer = linkElement.nextElementSibling;
        if (!dataContainer || !dataContainer.classList.contains('card-link-data')) {
             return;
         }
         }
          
 
         var overlay = document.getElementById('card-overlay');
         // 在隐藏容器中查找卡牌
        var container = document.getElementById('card-display-container');
         var cardWrapper = dataContainer.querySelector('.card-small-wrapper');
       
         if (!cardWrapper) {
        // 添加到历史栈
             return;
         if (addToHistory) {
             viewHistory.push({
                type: 'derivedCards',
                data: {
                    character: character,
                    derivedCardsList: derivedCardsList
                }
            });
         }
         }
        // 克隆卡牌
        var clonedCard = cardWrapper.cloneNode(true);
        clonedCard.style.cursor = 'default';
          
          
         // 清空当前内容
         // 移除可能触发模态框的属性和类
         container.innerHTML = '';
         clonedCard.removeAttribute('data-card-id');
        container.style.cssText = 'position: relative; padding: 40px; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;';
         var originalClass = clonedCard.className;
       
         clonedCard.className = originalClass.replace('card-small-wrapper', 'card-hover-preview');
        // 创建标题
 
        var title = document.createElement('div');
         // 创建弹出框
        title.style.cssText = 'color: white; font-size: 28px; font-weight: bold; margin-bottom: 30px; text-align: center;';
         var popup = document.createElement('div');
        title.textContent = '衍生卡牌';
         popup.className = 'card-hover-popup';
        container.appendChild(title);
         popup.appendChild(clonedCard);
       
 
        // 创建卡牌容器
         // 添加到链接中
         var cardsContainer = document.createElement('div');
         linkElement.appendChild(popup);
        cardsContainer.style.cssText = 'display: flex; flex-wrap: wrap; gap: 30px; justify-content: center; max-width: 1400px; transform: scale(1.5); transform-origin: center center; padding: 40px;';
       
        // 加载所有衍生卡牌
        var uniqueCards = [...new Set(derivedCardsList.map(function(name) { return name.trim(); }))];
        var loadedCount = 0;
          
        uniqueCards.forEach(function(cardName) {
            fetchCardHTML(character, cardName, '', function(html) {
                var cardWrapper = document.createElement('div');
                cardWrapper.innerHTML = html;
                var cards = cardWrapper.querySelectorAll('.game-card');
                cards.forEach(function(card) {
                    // 禁用点击事件
                    card.style.cursor = 'default';
                    card.onclick = function(e) {
                        e.stopPropagation();
                        e.preventDefault();
                    };
                   
                    // 检查是否有衍生卡牌
                    var derivedCards = card.dataset.derivedCards;
                    if (derivedCards && derivedCards.trim() !== '') {
                        // 创建衍生卡牌按钮容器
                        var buttonContainer = document.createElement('div');
                        buttonContainer.style.cssText = 'display: flex; flex-direction: column; align-items: center; gap: 10px;';
                       
                        // 创建卡片容器
                        var cardContainer = document.createElement('div');
                        cardContainer.appendChild(card.cloneNode(true));
                        buttonContainer.appendChild(cardContainer);
                       
                        // 创建查看衍生卡牌按钮
                        var viewDerivedBtn = document.createElement('div');
                        viewDerivedBtn.style.cssText = 'padding: 8px 15px; background: linear-gradient(135deg, #4a90e2, #357abd); color: white; border-radius: 6px; cursor: pointer; white-space: nowrap; font-weight: bold; box-shadow: 0 2px 8px rgba(0,0,0,0.3); transition: transform 0.2s; font-size: 12px;';
                        viewDerivedBtn.textContent = '查看衍生卡牌';
                        viewDerivedBtn.onmouseover = function() { this.style.transform = 'scale(1.05)'; };
                        viewDerivedBtn.onmouseout = function() { this.style.transform = 'scale(1)'; };
                        viewDerivedBtn.onclick = function(e) {
                            e.stopPropagation();
                            showAllDerivedCards(character, derivedCards.split('、'));
                        };
                       
                        buttonContainer.appendChild(viewDerivedBtn);
                        cardsContainer.appendChild(buttonContainer);
                    } else {
                        cardsContainer.appendChild(card);
                    }
                });
               
                loadedCount++;
                if (loadedCount === uniqueCards.length) {
                    // 所有卡牌加载完成
                }
            });
        });
       
        container.appendChild(cardsContainer);
       
         // 添加返回按钮
         var backBtn = document.createElement('div');
         backBtn.style.cssText = 'position: fixed; top: 20px; left: 20px; padding: 10px 20px; background: linear-gradient(135deg, #4a90e2, #357abd); color: white; border-radius: 6px; cursor: pointer; font-weight: bold; box-shadow: 0 2px 8px rgba(0,0,0,0.3); z-index: 10001; transition: transform 0.2s;';
         backBtn.textContent = '← 返回';
        backBtn.onmouseover = function() { this.style.transform = 'scale(1.05)'; };
        backBtn.onmouseout = function() { this.style.transform = 'scale(1)'; };
        backBtn.onclick = function() {
            goBack(); // 使用新的返回函数
        };
        container.appendChild(backBtn);
       
         // 添加关闭按钮
         container.appendChild(createCloseButton());
     }
     }
   
 
    // 检查卡牌变体
     function hideCardPopup(linkElement) {
     function checkCardVariants(character, cardName, callback) {
         hoverTimeout = setTimeout(function () {
         var variants = { lingguang: false, shenguang: false };
            var popup = linkElement.querySelector('.card-hover-popup');
        var checkCount = 0;
             if (popup) {
        var totalChecks = 2;
                 popup.remove();
       
        function checkComplete() {
            checkCount++;
             if (checkCount === totalChecks) {
                 callback(variants);
             }
             }
         }
         }, 100);
       
    }
        // 并行检查两种变体
 
         fetchCardHTML(character, cardName, '灵光一闪', function(html) {
    function initCardLinks() {
             if (html && !html.includes('找不到卡组')) {
         var cardLinks = document.querySelectorAll('.card-link');
                 variants.lingguang = true;
 
        cardLinks.forEach(function (link) {
            // 避免重复绑定
             if (link.hasAttribute('data-card-hover-init')) {
                 return;
             }
             }
             checkComplete();
             link.setAttribute('data-card-hover-init', 'true');
        });
 
       
            // 添加事件监听器
        fetchCardHTML(character, cardName, '神之一闪', function(html) {
            link.addEventListener('mouseenter', function () {
             if (html && !html.includes('找不到卡组')) {
                showCardPopup(link);
                 variants.shenguang = true;
            });
             }
 
            checkComplete();
             link.addEventListener('mouseleave', function () {
                 hideCardPopup(link);
             });
         });
         });
     }
     }
    // 初始化
    function init() {
        initCardLinks();
    }
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
    // MediaWiki 钩子支持
    if (typeof mw !== 'undefined' && mw.hook) {
        mw.hook('wikipage.content').add(init);
    }
})();
/* 切换标签 */
(function() {
    'use strict';
      
      
    // 显示变体卡牌 - 添加 addToHistory 参数
     function initTabSwitcher() {
     function showVariantCards(character, cardName, variantType, addToHistory) {
         var tabContainers = document.querySelectorAll('.resp-tabs');
         if (addToHistory !== false) {
            addToHistory = true;
        }
          
          
         var overlay = document.getElementById('card-overlay');
         tabContainers.forEach(function(container) {
        var container = document.getElementById('card-display-container');
            var tabButtons = container.querySelectorAll('.czn-list-style');
       
            if (tabButtons.length === 0) return;
        // 添加到历史栈
           
        if (addToHistory) {
            var tabContents = container.querySelectorAll('.resp-tab-content');
            viewHistory.push({
           
                type: 'variantCards',
            // 初始化
                data: {
            tabButtons.forEach(function(button, index) {
                    character: character,
                button.classList.toggle('active', index === 0);
                    cardName: cardName,
                    variantType: variantType
                }
             });
             });
        }
       
        // 重置容器样式
        container.style.cssText = 'position: relative; padding: 40px; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;';
        container.innerHTML = '';
       
        // 创建标题
        var title = document.createElement('div');
        title.style.cssText = 'color: white; font-size: 28px; font-weight: bold; margin-bottom: 30px; text-align: center; background: linear-gradient(135deg, #667eea, #764ba2); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;';
        title.textContent = cardName + ' - ' + variantType;
        container.appendChild(title);
       
        // 创建卡牌容器
        var cardsContainer = document.createElement('div');
        cardsContainer.style.cssText = 'display: flex; flex-wrap: nowrap; gap: 0px; justify-content: center; max-width: 1400px; overflow-x: auto; padding: 40px; transform: scale(1.5); transform-origin: center center;';
       
        // 加载变体卡牌
        fetchCardHTML(character, cardName, variantType, function(html) {
            var tempContainer = document.createElement('div');
            tempContainer.innerHTML = html;
              
              
             // 处理所有卡牌
             if (tabContents.length > 0) {
            var cards = tempContainer.querySelectorAll('.game-card');
                tabContents.forEach(function(content, index) {
                    content.style.display = index === 0 ? 'block' : 'none';
                });
            }
              
              
             cards.forEach(function(card, index) {
             // 点击事件
                 card.style.cursor = 'default';
            tabButtons.forEach(function(button, index) {
                card.onclick = null;
                 button.addEventListener('click', function(e) {
                card.style.flexShrink = '0';
                     e.preventDefault();
               
                // 获取衍生卡牌数据
                var derivedCards = card.getAttribute('data-derived-cards');
               
                // 更严格的检查
                var hasDerivedCards = false;
                if (derivedCards !== null && derivedCards !== undefined) {
                    var trimmedValue = String(derivedCards).trim();
                    if (trimmedValue.length > 0 &&
                        trimmedValue !== 'undefined' &&
                        trimmedValue !== 'null' &&
                        trimmedValue !== 'false' &&
                        trimmedValue !== '0') {
                        hasDerivedCards = true;
                        console.log('卡牌 ' + index + ' 有衍生卡牌:', trimmedValue);
                    } else {
                        console.log('卡牌 ' + index + ' 衍生卡牌为空或无效:', derivedCards);
                    }
                } else {
                    console.log('卡牌 ' + index + ' 没有衍生卡牌属性');
                }
               
                if (hasDerivedCards) {
                     // 创建包装器,包含卡牌和按钮
                    var cardWrapper = document.createElement('div');
                    cardWrapper.style.cssText = 'display: flex; flex-direction: column; align-items: center; gap: 10px; flex-shrink: 0;';
                      
                      
                     // 添加卡牌
                     // 更新标签状态
                     var cardClone = card.cloneNode(true);
                     tabButtons.forEach(function(btn, i) {
                    cardClone.style.cursor = 'default';
                        btn.classList.toggle('active', i === index);
                    cardClone.onclick = null;
                     });
                     cardWrapper.appendChild(cardClone);
                      
                      
                     // 创建查看衍生卡牌按钮
                     // 切换内容
                     var viewDerivedBtn = document.createElement('div');
                     if (tabContents.length > 0) {
                    viewDerivedBtn.style.cssText = 'padding: 8px 15px; background: linear-gradient(135deg, #4a90e2, #357abd); color: white; border-radius: 6px; cursor: pointer; white-space: nowrap; font-weight: bold; box-shadow: 0 2px 8px rgba(0,0,0,0.3); transition: transform 0.2s; font-size: 12px;';
                        tabContents.forEach(function(content, i) {
                    viewDerivedBtn.textContent = '查看衍生卡牌';
                            content.style.display = i === index ? 'block' : 'none';
                    viewDerivedBtn.onmouseover = function() { this.style.transform = 'scale(1.05)'; };
                         });
                    viewDerivedBtn.onmouseout = function() { this.style.transform = 'scale(1)'; };
                     }
                   
                 });
                    // 保存衍生卡牌信息
                    viewDerivedBtn.setAttribute('data-derived-list', derivedCards);
                    viewDerivedBtn.onclick = function(e) {
                         e.stopPropagation();
                        var derivedList = this.getAttribute('data-derived-list');
                        showAllDerivedCards(character, derivedList.split('、'));
                     };
                   
                    cardWrapper.appendChild(viewDerivedBtn);
                    cardsContainer.appendChild(cardWrapper);
                 } else {
                    // 没有衍生卡牌,直接添加卡牌
                    cardsContainer.appendChild(card);
                }
             });
             });
        });
       
        container.appendChild(cardsContainer);
       
        // 添加返回按钮
        var backBtn = document.createElement('div');
        backBtn.style.cssText = 'position: fixed; top: 20px; left: 20px; padding: 10px 20px; background: linear-gradient(135deg, #4a90e2, #357abd); color: white; border-radius: 6px; cursor: pointer; font-weight: bold; box-shadow: 0 2px 8px rgba(0,0,0,0.3); z-index: 10001; transition: transform 0.2s;';
        backBtn.textContent = '← 返回';
        backBtn.onmouseover = function() { this.style.transform = 'scale(1.05)'; };
        backBtn.onmouseout = function() { this.style.transform = 'scale(1)'; };
        backBtn.onclick = function() {
            goBack(); // 使用新的返回函数
        };
        container.appendChild(backBtn);
       
        // 添加关闭按钮
        container.appendChild(createCloseButton());
    }
    // 初始化卡牌点击事件
    function initCardClickEvents() {
        // 使用事件委托
        document.addEventListener('click', function(e) {
            var card = e.target.closest('.game-card');
            if (card && !card.closest('#card-overlay')) {
                e.preventDefault();
                showEnlargedCard(card);
            }
         });
         });
     }
     }
      
      
     // 页面加载完成后初始化
     // 初始化
     if (document.readyState === 'loading') {
     if (document.readyState === 'loading') {
         document.addEventListener('DOMContentLoaded', function() {
         document.addEventListener('DOMContentLoaded', initTabSwitcher);
            initCardClickEvents();
        });
     } else {
     } else {
         initCardClickEvents();
         initTabSwitcher();
     }
     }
})();
})();
第825行: 第595行:
     $(document).on('mouseleave', '.character-switch-btn:not(.active)', function() {
     $(document).on('mouseleave', '.character-switch-btn:not(.active)', function() {
         $(this).css('background', 'rgba(0,0,0,0.5)');
         $(this).css('background', 'rgba(0,0,0,0.5)');
    });
});
/* 轮播图 */
$(function() {
    $('.carousel-container').each(function() {
        var $container = $(this);
        var $wrapper = $container.find('.carousel-wrapper');
        var $slides = $container.find('.carousel-slide');
        var $titleItems = $container.find('.carousel-title-item');
        var slideCount = $slides.length;
        var currentSlide = 0;
        var autoPlayInterval;
        var isTransitioning = false;
       
        // 切换到指定幻灯片
        function goToSlide(index) {
            if (isTransitioning) return;
           
            if (index < 0) index = slideCount - 1;
            if (index >= slideCount) index = 0;
           
            isTransitioning = true;
            currentSlide = index;
            $wrapper.css('transform', 'translateX(-' + (index * 100) + '%)');
           
            // 更新标题状态
            $titleItems.each(function(i) {
                var $item = $(this);
                var $text = $item.find('.title-text');
                var $indicator = $item.find('.title-indicator');
               
                if (i === index) {
                    $item.addClass('active');
                    $text.css('opacity', '1').css('font-weight', 'bold');
                    $indicator.css('background', '#ff6600');
                } else {
                    $item.removeClass('active');
                    $text.css('opacity', '0.7').css('font-weight', 'normal');
                    $indicator.css('background', 'transparent');
                }
            });
           
            setTimeout(function() {
                isTransitioning = false;
            }, 500);
        }
       
        // 下一张
        function nextSlide() {
            goToSlide(currentSlide + 1);
        }
       
        // 上一张
        function prevSlide() {
            goToSlide(currentSlide - 1);
        }
       
        // 自动播放
        function startAutoPlay() {
            autoPlayInterval = setInterval(nextSlide, 10000);
        }
       
        // 停止自动播放
        function stopAutoPlay() {
            clearInterval(autoPlayInterval);
        }
       
        // 绑定左右切换按钮事件(处理图片点击)
        $container.find('.carousel-next').click(function(e) {
            e.preventDefault();
            e.stopPropagation();
            stopAutoPlay();
            nextSlide();
            startAutoPlay();
        });
       
        $container.find('.carousel-prev').click(function(e) {
            e.preventDefault();
            e.stopPropagation();
            stopAutoPlay();
            prevSlide();
            startAutoPlay();
        });
       
        // 防止按钮内的图片链接跳转
        $container.find('.carousel-btn img, .carousel-btn a').click(function(e) {
            e.preventDefault();
            return false;
        });
       
        // 绑定标题点击事件
        $titleItems.click(function() {
            var slideIndex = parseInt($(this).attr('data-slide'));
            stopAutoPlay();
            goToSlide(slideIndex);
            startAutoPlay();
        });
       
        // 鼠标悬停在容器时暂停
        $container.hover(
            function() { stopAutoPlay(); },
            function() { startAutoPlay(); }
        );
       
        // 触摸滑动支持(移动设备)
        var touchStartX = 0;
        var touchEndX = 0;
       
        $container.on('touchstart', function(e) {
            touchStartX = e.originalEvent.changedTouches[0].screenX;
        });
       
        $container.on('touchend', function(e) {
            touchEndX = e.originalEvent.changedTouches[0].screenX;
            handleSwipe();
        });
       
        function handleSwipe() {
            if (touchEndX < touchStartX - 50) {
                stopAutoPlay();
                nextSlide();
                startAutoPlay();
            }
            if (touchEndX > touchStartX + 50) {
                stopAutoPlay();
                prevSlide();
                startAutoPlay();
            }
        }
       
        // 键盘控制
        $(document).keydown(function(e) {
            if ($container.is(':hover')) {
                if (e.keyCode === 37) { // 左箭头
                    stopAutoPlay();
                    prevSlide();
                    startAutoPlay();
                } else if (e.keyCode === 39) { // 右箭头
                    stopAutoPlay();
                    nextSlide();
                    startAutoPlay();
                }
            }
        });
       
        // 启动自动播放
        if (slideCount > 1) {
            startAutoPlay();
        }
     });
     });
});
});
第1,037行: 第657行:
});
});


/* 卡牌悬浮 */
/* 词典Tooltip */
$(function() {
  // 初始化所有卡牌悬浮
  function initCardHoverElements() {
    $('.card-hover-container').each(function() {
      var $container = $(this);
     
      // 只初始化尚未处理的元素
      if ($container.data('initialized')) return;
     
      $container.data('initialized', true);
     
      // 获取卡牌数据
      var character = $container.data('character');
      var cardName = $container.data('card');
      var deckType = $container.data('deck') || '';
      var index = $container.data('index') || 0;
      var $popup = $container.find('.card-popup');
     
      // 预加载卡牌数据
      $container.on('mouseenter', function() {
        // 如果卡牌数据已经加载过,直接显示
        if ($popup.data('loaded')) {
          // 调整位置到右下方
          positionCardPopup($container);
          return;
        }
       
        // 加载卡牌数据
        var params = {
          action: 'parse',
          text: '{{#invoke:卡牌|main|' + character + '|' + cardName + '|' + deckType + '|' + index + '}}',
          prop: 'text',
          disablelimitreport: true,
          format: 'json'
        };
       
        $.ajax({
          url: mw.util.wikiScript('api'),
          data: params,
          dataType: 'json',
          success: function(data) {
            if (data && data.parse && data.parse.text) {
              var cardHtml = data.parse.text['*'];
              $popup.html(cardHtml).data('loaded', true);
             
              // 调整位置到右下方
              positionCardPopup($container);
            }
          },
          error: function() {
            $popup.html('<div style="color: #721c24;">无法加载卡牌数据</div>').data('loaded', true);
          }
        });
      });
    });
  }
 
  // 调整卡牌弹出位置到右下方
  function positionCardPopup($container) {
    var $popupContainer = $container.find('.card-popup-container');
    var containerWidth = $container.width();
    var windowWidth = $(window).width();
    var containerOffset = $container.offset();
    var rightSpace = windowWidth - containerOffset.left - containerWidth;
   
    // 重置位置
    $popupContainer.css({
      'left': 'auto',
      'right': 'auto',
      'top': '100%',
      'margin-top': '5px'
    });
   
    // 如果右侧空间足够,放在右下方
    if (rightSpace >= 168) { // 卡牌宽度大约168px
      $popupContainer.css({
        'left': '0',
      });
    }
    // 如果右侧空间不够,但左侧空间足够,放在左下方
    else if (containerOffset.left >= 168) {
      $popupContainer.css({
        'right': '0',
      });
    }
    // 如果两侧都不够,尝试居中并确保完全可见
    else {
      var leftPosition = Math.max(0, Math.min(containerOffset.left - (168/2), windowWidth - 168));
      $popupContainer.css({
        'left': (leftPosition - containerOffset.left) + 'px'
      });
    }
  }
 
  // 初次加载页面时初始化
  $(document).ready(function() {
    initCardHoverElements();
  });
 
  // 使用 MutationObserver 监听 DOM 变化,处理动态加载的内容
  if (window.MutationObserver) {
    var observer = new MutationObserver(function(mutations) {
      var shouldInit = false;
      mutations.forEach(function(mutation) {
        if (mutation.addedNodes && mutation.addedNodes.length) {
          shouldInit = true;
        }
      });
     
      if (shouldInit) {
        initCardHoverElements();
      }
    });
   
    observer.observe(document.body, {
      childList: true,
      subtree: true
    });
  }
});
 
// 词典 tooltip 系统
(function() {
(function() {
     var tooltipContainer = null;
     var tooltipContainer = null;
第1,267行: 第765行:
})();
})();


/* 卡牌文字滚动 */
/* 轮播图 */
(function() {
(function () {
    'use strict';
  'use strict';
 
  function initCarousel(root) {
    if (!root || root.__inited) return;
    root.__inited = true;
 
    const wrapper = root.querySelector('.carousel-wrapper');
    const slides = Array.from(root.querySelectorAll('.carousel-slide'));
    const titles = Array.from(root.querySelectorAll('.carousel-title-item'));
    const btnPrev = root.querySelector('.carousel-prev');
    const btnNext = root.querySelector('.carousel-next');
 
    if (!wrapper || !slides.length) {
      root.style.display = 'none';
      return;
    }
 
    // 单张图隐藏按钮
    if (slides.length === 1) {
      root.classList.add('single');
    }
 
    // 标题索引与幻灯索引对齐
    titles.forEach((t, i) => {
      t.dataset.slide = String(i);
    });
 
    let index = 0;
    let timer = null;
    const autoplay = (root.getAttribute('data-autoplay') || '1') !== '0';
    const interval = Math.max(1500, parseInt(root.getAttribute('data-interval') || '4000', 10) || 4000);
 
    function update() {
      wrapper.style.transform = 'translateX(' + (-index * 100) + '%)';
      titles.forEach((t, i) => {
        if (i === index) t.classList.add('active');
        else t.classList.remove('active');
 
        const text = t.querySelector('.title-text');
        const ind = t.querySelector('.title-indicator');
        if (text) text.style.opacity = i === index ? '1' : '0.75';
        if (ind) ind.style.background = i === index ? '#ff6600' : 'transparent';
      });
    }
 
    function next() {
      index = (index + 1) % slides.length;
      update();
    }
 
    function prev() {
      index = (index - 1 + slides.length) % slides.length;
      update();
    }
 
    // 标题点击
    titles.forEach((t) => {
      t.addEventListener('click', function () {
        const i = parseInt(t.dataset.slide || '0', 10) || 0;
        index = Math.min(Math.max(i, 0), slides.length - 1);
        update();
        restartAutoplay();
      });
    });
 
    // 按钮点击
    if (btnPrev) {
      btnPrev.addEventListener('click', function () {
        prev();
        restartAutoplay();
      });
    }
    if (btnNext) {
      btnNext.addEventListener('click', function () {
        next();
        restartAutoplay();
      });
    }
 
    // 自动播放控制
    function startAutoplay() {
      if (!autoplay || slides.length <= 1) return;
      stopAutoplay();
      timer = setInterval(next, interval);
    }
 
    function stopAutoplay() {
      if (timer) {
        clearInterval(timer);
        timer = null;
      }
    }
 
    function restartAutoplay() {
      stopAutoplay();
      startAutoplay();
    }
 
    // 悬停/聚焦暂停
    root.addEventListener('mouseenter', stopAutoplay);
    root.addEventListener('mouseleave', startAutoplay);
    root.addEventListener('focusin', stopAutoplay);
    root.addEventListener('focusout', startAutoplay);
 
    // 触摸滑动
    let startX = 0;
    let curX = 0;
    let dragging = false;
    const threshold = 30;
 
    root.addEventListener(
      'touchstart',
      function (e) {
        if (!e.touches || !e.touches.length) return;
        startX = e.touches[0].clientX;
        curX = startX;
        dragging = true;
        root.classList.add('grabbing');
        stopAutoplay();
      },
      { passive: true }
    );
 
    root.addEventListener(
      'touchmove',
      function (e) {
        if (!dragging || !e.touches || !e.touches.length) return;
        curX = e.touches[0].clientX;
        const dx = curX - startX;
        wrapper.style.transform = 'translateX(calc(' + (-index * 100) + '% + ' + dx + 'px))';
      },
      { passive: true }
    );
 
    root.addEventListener('touchend', function () {
      if (!dragging) return;
      const dx = curX - startX;
      root.classList.remove('grabbing');
      dragging = false;
      if (Math.abs(dx) > threshold) {
        if (dx < 0) next();
        else prev();
      } else {
        update();
      }
      startAutoplay();
    });
 
    // 鼠标拖动(可选)
    let mouseDown = false;
    let mStartX = 0;
 
    root.addEventListener('mousedown', function (e) {
      mouseDown = true;
      mStartX = e.clientX;
      root.classList.add('grab');
      stopAutoplay();
    });
 
    window.addEventListener('mouseup', function (e) {
      if (!mouseDown) return;
      const dx = e.clientX - mStartX;
      mouseDown = false;
      root.classList.remove('grab');
      if (Math.abs(dx) > threshold) {
        if (dx < 0) next();
        else prev();
      } else {
        update();
      }
      startAutoplay();
    });
 
    // 初始化
    update();
    startAutoplay();
  } // <- 确保此处仅关闭 initCarousel 函数
 
  function initAll(context) {
    const scope = context && context.querySelectorAll ? context : document;
    scope.querySelectorAll('.carousel-container').forEach(initCarousel);
  }
 
  // 初次加载
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', function () {
      initAll();
    });
  } else {
    initAll();
  }
 
  // 动态内容(如可视化编辑器或AJAX)再次初始化
  if (window.mw && mw.hook) {
    mw.hook('wikipage.content').add(function (content) {
      // content 可能是 jQuery 对象,也可能是原生节点
      if (content && content[0] && content.find) {
        // jQuery 对象
        content.find('.carousel-container').each(function () {
          initCarousel(this);
        });
      } else if (content && content.querySelectorAll) {
        // 原生节点
        initAll(content);
      } else {
        initAll();
      }
    });
  }
})();
 
/* 装备 */
$(function() {
    // 创建遮罩层
    if ($('.equipment-wrapper').length > 0 && $('#equipment-overlay').length === 0) {
        $('body').append('<div id="equipment-overlay" class="equipment-overlay"></div>');
    }
      
      
     function initCardScroll() {
     // 点击装备卡片显示弹窗
         var cards = document.querySelectorAll('.game-card.card-description-scrollable');
    $(document).on('click', '.equipment-card', function(e) {
        e.stopPropagation();
       
         var equipName = $(this).attr('data-equipment');
        var level = $(this).attr('data-level');
        var popup = $(this).closest('.equipment-wrapper').find('.equipment-popup');
          
          
         cards.forEach(function(card) {
         if (popup.length > 0) {
             var scrollContainer = card.querySelector('.card-description-scroll');
             $('#equipment-overlay').fadeIn(200);
            var scrollInner = card.querySelector('.card-description-scroll-inner');
             popup.fadeIn(200);
             var scrollText = card.querySelector('.card-description-text');
        }
           
    });
            if (!scrollContainer || !scrollInner || !scrollText) {
   
                return;
    // 防止点击装备名称链接时触发其他事件
            }
    $(document).on('click', '.equipment-name-link a', function(e) {
           
        e.stopPropagation();
            // 强制触发重绘
        // 允许默认的链接跳转行为
            scrollInner.style.display = 'none';
    });
            scrollInner.offsetHeight; // 触发重排
            scrollInner.style.display = 'block';
        });
    }
      
      
     // 延迟初始化,确保DOM完全加载
     // 点击关闭按钮关闭弹窗
     function delayedInit() {
     $(document).on('click', '.equipment-popup-close', function(e) {
         setTimeout(initCardScroll, 100);
         e.stopPropagation();
         setTimeout(initCardScroll, 500);
         $(this).parent('.equipment-popup').fadeOut(200);
         setTimeout(initCardScroll, 1000);
         $('#equipment-overlay').fadeOut(200);
     }
     });
      
      
     if (document.readyState === 'loading') {
     // 点击遮罩层关闭弹窗
         document.addEventListener('DOMContentLoaded', delayedInit);
    $(document).on('click', '#equipment-overlay', function() {
    } else {
         $('.equipment-popup:visible').fadeOut(200);
         delayedInit();
         $(this).fadeOut(200);
     }
     });
      
      
})();
    // 点击弹窗内容不关闭
    $(document).on('click', '.equipment-popup', function(e) {
        e.stopPropagation();
    });
});

2025年11月5日 (三) 21:34的最新版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */

// 等待 mw 对象加载完成
mw.loader.using(['mediawiki.util'], function() {
    
    // 动态加载 PIXI.js
    function loadScript(url) {
        return new Promise(function(resolve, reject) {
            var script = document.createElement('script');
            script.src = url;
            script.onload = resolve;
            script.onerror = reject;
            document.head.appendChild(script);
        });
    }
    
    // 按顺序加载库
    loadScript('https://cdn.jsdelivr.net/npm/pixi.js@5.3.12/dist/pixi.min.js')
        .then(function() {
            return loadScript('https://cdn.jsdelivr.net/npm/pixi-spine@3.0.12/dist/pixi-spine.js');
        })
        .then(function() {
            console.log('Spine libraries loaded successfully');
            initSpinePlayers();
        })
        .catch(function(error) {
            console.error('Failed to load Spine libraries:', error);
        });
    
    function initSpinePlayers() {
        var containers = document.querySelectorAll('.spine-player-container');
        
        if (containers.length === 0) {
            console.log('No spine containers found');
            return;
        }
        
        containers.forEach(function(container) {
            var skelUrl = container.getAttribute('data-skel');
            var atlasUrl = container.getAttribute('data-atlas');
            var animationName = container.getAttribute('data-animation') || 'idle';
            var skinName = container.getAttribute('data-skin') || 'default';
            
            if (!skelUrl || !atlasUrl) {
                console.error('Missing skel or atlas URL');
                return;
            }
            
            // 创建 PIXI 应用
            var app = new PIXI.Application({
                width: container.clientWidth || 800,
                height: container.clientHeight || 600,
                backgroundColor: 0x2c3e50,
                transparent: false
            });
            
            container.innerHTML = '';
            container.appendChild(app.view);
            
            // 加载 Spine 资源
            app.loader
                .add('spineData', skelUrl)
                .load(function(loader, resources) {
                    try {
                        var animation = new PIXI.spine.Spine(resources.spineData.spineData);
                        
                        // 设置位置和缩放
                        animation.x = app.screen.width / 2;
                        animation.y = app.screen.height / 2;
                        animation.scale.set(0.5);
                        
                        // 播放动画
                        if (animation.state.hasAnimation(animationName)) {
                            animation.state.setAnimation(0, animationName, true);
                        }
                        
                        app.stage.addChild(animation);
                        console.log('Spine animation loaded successfully');
                    } catch(e) {
                        console.error('Error creating spine animation:', e);
                    }
                });
        });
    }
});

/* 卡牌 */
(function () {
    'use strict';

    var initialized = false;

    function show(el) {
        if (el) el.style.display = 'flex';
    }
    function hide(el) {
        if (el) el.style.display = 'none';
    }

    function resetModalView(modal) {
        var originalView = modal.querySelector('.original-card-view');
        var inspirationView = modal.querySelector('.inspiration-view');
        var godView = modal.querySelector('.god-inspiration-view');
        var subcardsView = modal.querySelector('.subcards-view');
        var nestedSubcardsViews = modal.querySelectorAll('.nested-subcards-view');
        var inspirationNestedViews = modal.querySelectorAll('.inspiration-subcards-view');
        var inspirationDeeperNestedViews = modal.querySelectorAll('.inspiration-nested-subcards-view');

        if (originalView) show(originalView);
        if (inspirationView) hide(inspirationView);
        if (godView) hide(godView);
        if (subcardsView) hide(subcardsView);

        nestedSubcardsViews.forEach(hide);
        inspirationNestedViews.forEach(hide);
        inspirationDeeperNestedViews.forEach(hide);
    }

    function closeModal(modal) {
        modal.style.display = 'none';
        document.body.style.overflow = 'auto';
        resetModalView(modal);
    }

    function openModalFromCard(cardWrapper) {
        var cardId = cardWrapper.getAttribute('data-card-id');
        if (!cardId) return;
        var modal = document.getElementById(cardId + '-modal');
        if (!modal) return;
        resetModalView(modal);
        modal.style.display = 'block';
        document.body.style.overflow = 'hidden';
    }

    function handleBackToCard(button) {
        var modal = button.closest('.card-modal');
        if (modal) {
            resetModalView(modal);
        }
    }

    function handleBackToSubcards(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var nestedView = button.closest('.nested-subcards-view');
        var subcardsView = modal.querySelector('.subcards-view');
        if (nestedView && subcardsView) {
            hide(nestedView);
            show(subcardsView);
        }
    }

    function handleInspirationClick(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var originalView = modal.querySelector('.original-card-view');
        var inspirationView = modal.querySelector('.inspiration-view');
        if (!originalView || !inspirationView) return;
        hide(originalView);
        show(inspirationView);
    }

    function handleGodInspirationClick(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var originalView = modal.querySelector('.original-card-view');
        var godView = modal.querySelector('.god-inspiration-view');
        if (!originalView || !godView) return;
        hide(originalView);
        show(godView);
    }

    function handleSubcardsClick(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var originalView = modal.querySelector('.original-card-view');
        var subcardsView = modal.querySelector('.subcards-view');
        if (!originalView || !subcardsView) return;
        hide(originalView);
        show(subcardsView);
    }

    function handleViewNestedSubcardsClick(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var subcardIndex = button.getAttribute('data-subcard-index');
        if (!subcardIndex) return;
        var subcardsView = modal.querySelector('.subcards-view');
        var nestedView = modal.querySelector('.nested-subcards-view[data-subcard-index="' + subcardIndex + '"]');
        if (!subcardsView || !nestedView) return;
        hide(subcardsView);
        show(nestedView);
    }

    function handleInspirationSubcardsClick(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var idx = button.getAttribute('data-variant-index');
        if (!idx) return;
        var inspirationView = modal.querySelector('.inspiration-view');
        var nestedView = modal.querySelector('.inspiration-subcards-view[data-variant-index="' + idx + '"]');
        if (!inspirationView || !nestedView) return;
        hide(inspirationView);
        show(nestedView);
    }

    function handleBackToInspiration(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var nestedView = button.closest('.inspiration-subcards-view');
        var inspirationView = modal.querySelector('.inspiration-view');
        if (nestedView && inspirationView) {
            hide(nestedView);
            show(inspirationView);
        }
    }

    function handleViewInspirationNestedSubcardsClick(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var vIdx = button.getAttribute('data-variant-index');
        var sIdx = button.getAttribute('data-subcard-index');
        if (!vIdx || !sIdx) return;
        var subcardsView = modal.querySelector('.inspiration-subcards-view[data-variant-index="' + vIdx + '"]');
        var deeperView = modal.querySelector('.inspiration-nested-subcards-view[data-variant-index="' + vIdx + '"][data-subcard-index="' + sIdx + '"]');
        if (!subcardsView || !deeperView) return;
        hide(subcardsView);
        show(deeperView);
    }

    function handleBackToInspirationSubcards(button) {
        var modal = button.closest('.card-modal');
        if (!modal) return;
        var deeperView = button.closest('.inspiration-nested-subcards-view');
        var vIdx = button.getAttribute('data-variant-index');
        var subcardsView = modal.querySelector('.inspiration-subcards-view[data-variant-index="' + vIdx + '"]');
        if (deeperView && subcardsView) {
            hide(deeperView);
            show(subcardsView);
        }
    }

    function onKeydown(event) {
        if (event.key === 'Escape' || event.keyCode === 27) {
            var modals = document.querySelectorAll('.card-modal');
            modals.forEach(function (modal) {
                if (modal.style.display === 'block') {
                    var inspirationView = modal.querySelector('.inspiration-view');
                    var godView = modal.querySelector('.god-inspiration-view');
                    var subcardsView = modal.querySelector('.subcards-view');
                    var nestedSubcardsViews = modal.querySelectorAll('.nested-subcards-view');
                    var inspirationNestedViews = modal.querySelectorAll('.inspiration-subcards-view');
                    var inspirationDeeperNestedViews = modal.querySelectorAll('.inspiration-nested-subcards-view');

                    var inNestedView = false;
                    nestedSubcardsViews.forEach(function (view) {
                        if (view.style.display !== 'none') {
                            inNestedView = true;
                            hide(view);
                            if (subcardsView) show(subcardsView);
                        }
                    });

                    var inInspirationNested = false;
                    inspirationNestedViews.forEach(function (view) {
                        if (view.style.display !== 'none') {
                            inInspirationNested = true;
                            hide(view);
                            if (inspirationView) show(inspirationView);
                        }
                    });

                    var inInspirationDeeperNested = false;
                    inspirationDeeperNestedViews.forEach(function (view) {
                        if (view.style.display !== 'none') {
                            inInspirationDeeperNested = true;
                            var vIdx = view.getAttribute('data-variant-index');
                            hide(view);
                            var parentSubcardsView = modal.querySelector('.inspiration-subcards-view[data-variant-index="' + vIdx + '"]');
                            if (parentSubcardsView) show(parentSubcardsView);
                        }
                    });

                    if (!inNestedView && !inInspirationNested && !inInspirationDeeperNested) {
                        if ((inspirationView && inspirationView.style.display !== 'none') ||
                            (subcardsView && subcardsView.style.display !== 'none') ||
                            (godView && godView.style.display !== 'none')) {
                            resetModalView(modal);
                        } else {
                            closeModal(modal);
                        }
                    }
                }
            });
        }
    }

    function onDocumentClick(e) {
        // 打开模态:点击卡片缩略图区域
        var cardWrapper = e.target.closest('.card-small-wrapper');
        if (cardWrapper) {
            e.preventDefault();
            e.stopPropagation();
            openModalFromCard(cardWrapper);
            return;
        }

        // 变体/衍生/返回/关闭
        if (e.target.classList.contains('inspiration-button')) {
            e.stopPropagation();
            handleInspirationClick(e.target);
            return;
        }
        if (e.target.classList.contains('god-inspiration-button')) {
            e.stopPropagation();
            handleGodInspirationClick(e.target);
            return;
        }
        if (e.target.classList.contains('subcards-button')) {
            e.stopPropagation();
            handleSubcardsClick(e.target);
            return;
        }
        if (e.target.classList.contains('view-nested-subcards-button')) {
            e.stopPropagation();
            handleViewNestedSubcardsClick(e.target);
            return;
        }
        if (e.target.classList.contains('back-to-card-button')) {
            e.stopPropagation();
            handleBackToCard(e.target);
            return;
        }
        if (e.target.classList.contains('back-to-subcards-button')) {
            e.stopPropagation();
            handleBackToSubcards(e.target);
            return;
        }
        if (e.target.classList.contains('view-insp-subcards-button')) {
            e.stopPropagation();
            handleInspirationSubcardsClick(e.target);
            return;
        }
        if (e.target.classList.contains('back-to-inspiration-button')) {
            e.stopPropagation();
            handleBackToInspiration(e.target);
            return;
        }
        if (e.target.classList.contains('view-insp-nested-subcards-button')) {
            e.stopPropagation();
            handleViewInspirationNestedSubcardsClick(e.target);
            return;
        }
        if (e.target.classList.contains('back-to-insp-subcards-button')) {
            e.stopPropagation();
            handleBackToInspirationSubcards(e.target);
            return;
        }

        // 关闭按钮
        var closeBtn = e.target.classList.contains('modal-close-button')
            ? e.target
            : (e.target.parentElement && e.target.parentElement.classList.contains('modal-close-button') ? e.target.parentElement : null);

        if (closeBtn) {
            var modal = closeBtn.closest('.card-modal');
            if (modal) closeModal(modal);
        }
    }

    function init() {
        if (initialized) return;
        initialized = true;

        document.addEventListener('click', onDocumentClick);
        document.addEventListener('keydown', onKeydown);
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }

    if (typeof mw !== 'undefined' && mw.hook) {
        // 页面增量渲染时确保已初始化(事件委托只需一次)
        mw.hook('wikipage.content').add(function () { init(); });
    }
})();

// 卡牌悬停显示功能
(function () {
    'use strict';

    var hoverTimeout;

    function showCardPopup(linkElement) {
        // 清除之前的超时
        if (hoverTimeout) {
            clearTimeout(hoverTimeout);
        }

        // 检查是否已有弹出框
        var existingPopup = linkElement.querySelector('.card-hover-popup');
        if (existingPopup) {
            return;
        }

        // 查找紧邻的隐藏数据容器
        var dataContainer = linkElement.nextElementSibling;
        if (!dataContainer || !dataContainer.classList.contains('card-link-data')) {
            return;
        }

        // 在隐藏容器中查找卡牌
        var cardWrapper = dataContainer.querySelector('.card-small-wrapper');
        if (!cardWrapper) {
            return;
        }

        // 克隆卡牌
        var clonedCard = cardWrapper.cloneNode(true);
        clonedCard.style.cursor = 'default';
        
        // 移除可能触发模态框的属性和类
        clonedCard.removeAttribute('data-card-id');
        var originalClass = clonedCard.className;
        clonedCard.className = originalClass.replace('card-small-wrapper', 'card-hover-preview');

        // 创建弹出框
        var popup = document.createElement('div');
        popup.className = 'card-hover-popup';
        popup.appendChild(clonedCard);

        // 添加到链接中
        linkElement.appendChild(popup);
    }

    function hideCardPopup(linkElement) {
        hoverTimeout = setTimeout(function () {
            var popup = linkElement.querySelector('.card-hover-popup');
            if (popup) {
                popup.remove();
            }
        }, 100);
    }

    function initCardLinks() {
        var cardLinks = document.querySelectorAll('.card-link');

        cardLinks.forEach(function (link) {
            // 避免重复绑定
            if (link.hasAttribute('data-card-hover-init')) {
                return;
            }
            link.setAttribute('data-card-hover-init', 'true');

            // 添加事件监听器
            link.addEventListener('mouseenter', function () {
                showCardPopup(link);
            });

            link.addEventListener('mouseleave', function () {
                hideCardPopup(link);
            });
        });
    }

    // 初始化
    function init() {
        initCardLinks();
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }

    // MediaWiki 钩子支持
    if (typeof mw !== 'undefined' && mw.hook) {
        mw.hook('wikipage.content').add(init);
    }
})();

/* 切换标签 */
(function() {
    'use strict';
    
    function initTabSwitcher() {
        var tabContainers = document.querySelectorAll('.resp-tabs');
        
        tabContainers.forEach(function(container) {
            var tabButtons = container.querySelectorAll('.czn-list-style');
            if (tabButtons.length === 0) return;
            
            var tabContents = container.querySelectorAll('.resp-tab-content');
            
            // 初始化
            tabButtons.forEach(function(button, index) {
                button.classList.toggle('active', index === 0);
            });
            
            if (tabContents.length > 0) {
                tabContents.forEach(function(content, index) {
                    content.style.display = index === 0 ? 'block' : 'none';
                });
            }
            
            // 点击事件
            tabButtons.forEach(function(button, index) {
                button.addEventListener('click', function(e) {
                    e.preventDefault();
                    
                    // 更新标签状态
                    tabButtons.forEach(function(btn, i) {
                        btn.classList.toggle('active', i === index);
                    });
                    
                    // 切换内容
                    if (tabContents.length > 0) {
                        tabContents.forEach(function(content, i) {
                            content.style.display = i === index ? 'block' : 'none';
                        });
                    }
                });
            });
        });
    }
    
    // 初始化
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initTabSwitcher);
    } else {
        initTabSwitcher();
    }
})();

/* 角色立绘切换 */
$(document).ready(function() {
    // 使用事件委托来确保动态内容也能响应
    $(document).on('click', '.character-switch-btn', function() {
        // 如果点击的是已经激活的按钮,不执行任何操作
        if ($(this).hasClass('active')) {
            return;
        }
        
        var targetType = $(this).attr('data-target');
        var container = $(this).closest('#character-container');
        var imageWrapper = container.find('.character-image-wrapper');
        var allImages = imageWrapper.find('.character-image');
        
        // 先将所有图片淡出
        allImages.each(function() {
            $(this).css('opacity', '0');
        });
        
        // 延迟后切换显示状态
        setTimeout(function() {
            allImages.each(function() {
                $(this).css('display', 'none');
            });
            
            // 显示目标图片
            imageWrapper.find('[data-image-type="' + targetType + '"]').each(function() {
                $(this).css('display', 'block');
                // 强制重绘
                $(this)[0].offsetHeight;
                $(this).css('opacity', '1');
            });
        }, 300);
        
        // 更新按钮样式
        container.find('.character-switch-btn').each(function() {
            $(this).removeClass('active');
            $(this).css({
                'background': 'rgba(0,0,0,0.5)',
                'cursor': 'pointer'
            });
        });
        
        // 设置当前按钮为激活状态
        $(this).addClass('active');
        $(this).css({
            'background': 'rgba(70, 130, 255, 0.8)',
            'cursor': 'default'
        });
    });
    
    // 鼠标悬停效果(仅对非激活按钮有效)
    $(document).on('mouseenter', '.character-switch-btn:not(.active)', function() {
        $(this).css('background', 'rgba(70, 130, 255, 0.5)');
    });
    
    $(document).on('mouseleave', '.character-switch-btn:not(.active)', function() {
        $(this).css('background', 'rgba(0,0,0,0.5)');
    });
});

/* 悬浮目录 */
$(document).ready(function() {
    // 只在有目录的页面上执行
    if ($('.toc').length > 0) {
        // 创建侧边目录
        var $sidebar = $('<div id="toc-sidebar"><div id="toc-sidebar-trigger">展开目录</div><div id="toc-sidebar-content"></div></div>');
        $('body').append($sidebar);
        
        // 提取并修复目录内容
        var tocUl = $('<ul></ul>');
        
        // 避免重复的目录项
        var processedItems = new Set();
        
        // 从原始目录构建新目录
        $('.toc ul li').each(function() {
            var $link = $(this).find('a').first();
            var href = $link.attr('href');
            var $number = $link.find('.tocnumber').first();
            var $text = $link.find('.toctext').first();
            
            // 创建唯一标识符,避免重复添加
            var itemId = $number.text() + '-' + $text.text();
            
            if (!processedItems.has(itemId)) {
                processedItems.add(itemId);
                
                // 创建新的目录项
                var $li = $('<li></li>');
                var $newLink = $('').attr('href', href);
                
                // 如果有编号,则添加编号
                if ($number.length) {
                    $newLink.append($('<span class="tocnumber"></span>').text($number.text()));
                    $newLink.append(' ');
                }
                
                $newLink.append($('<span class="toctext"></span>').text($text.text()));
                $li.append($newLink);
                tocUl.append($li);
            }
        });
        
        $('#toc-sidebar-content').append(tocUl);
        
        // 点击展开/折叠事件处理
        $('#toc-sidebar-trigger').click(function() {
            $('#toc-sidebar').toggleClass('expanded');
            
            // 根据展开/折叠状态更改按钮文字
            if ($('#toc-sidebar').hasClass('expanded')) {
                $('#toc-sidebar-trigger').text('隐藏目录');
            } else {
                $('#toc-sidebar-trigger').text('展开目录');
            }
        });
    }
});

/* 词典Tooltip */
(function() {
    var tooltipContainer = null;
    var currentTerm = null;
    var hideTimeout = null;
    
    // 初始化
    $(function() {
        // 创建全局 tooltip 容器
        tooltipContainer = $('<div class="dictionary-tooltip-container"></div>');
        $('body').append(tooltipContainer);
        
        // 鼠标进入词条
        $(document).on('mouseenter', '.dictionary-term', function(e) {
            var $term = $(this);
            currentTerm = $term;
            
            // 清除隐藏定时器
            if (hideTimeout) {
                clearTimeout(hideTimeout);
                hideTimeout = null;
            }
            
            // 获取 tooltip 内容
            var content = $term.attr('data-tooltip-content');
            if (!content) return;
            
            // 设置内容
            tooltipContainer.html(content);
            
            // 计算位置
            updateTooltipPosition($term);
            
            // 显示 tooltip
            tooltipContainer.addClass('active');
        });
        
        // 鼠标离开词条
        $(document).on('mouseleave', '.dictionary-term', function() {
            hideTimeout = setTimeout(function() {
                tooltipContainer.removeClass('active');
                currentTerm = null;
            }, 100);
        });
        
        // 鼠标进入 tooltip(防止快速隐藏)
        tooltipContainer.on('mouseenter', function() {
            if (hideTimeout) {
                clearTimeout(hideTimeout);
                hideTimeout = null;
            }
        });
        
        // 鼠标离开 tooltip
        tooltipContainer.on('mouseleave', function() {
            hideTimeout = setTimeout(function() {
                tooltipContainer.removeClass('active');
                currentTerm = null;
            }, 100);
        });
        
        // 窗口滚动时更新位置
        $(window).on('scroll resize', function() {
            if (currentTerm && tooltipContainer.hasClass('active')) {
                updateTooltipPosition(currentTerm);
            }
        });
    });
    
    // 更新 tooltip 位置
    function updateTooltipPosition($term) {
        var rect = $term[0].getBoundingClientRect();
        var scrollTop = $(window).scrollTop();
        var scrollLeft = $(window).scrollLeft();
        
        // 基本位置:词条下方
        var top = rect.bottom + scrollTop + 2;
        var left = rect.left + scrollLeft;
        
        // 获取 tooltip 尺寸
        var tooltipWidth = 250; // 固定宽度
        var tooltipHeight = tooltipContainer.outerHeight();
        
        // 获取窗口尺寸
        var windowWidth = $(window).width();
        var windowHeight = $(window).height();
        
        // 检查右边界
        if (left + tooltipWidth > windowWidth + scrollLeft) {
            left = Math.max(scrollLeft, rect.right + scrollLeft - tooltipWidth);
        }
        
        // 检查下边界
        if (rect.bottom + tooltipHeight > windowHeight) {
            // 如果下方空间不足,显示在上方
            if (rect.top - tooltipHeight > 0) {
                top = rect.top + scrollTop - tooltipHeight - 2;
            }
        }
        
        // 设置位置
        tooltipContainer.css({
            top: top + 'px',
            left: left + 'px'
        });
    }
})();

/* 轮播图 */
(function () {
  'use strict';

  function initCarousel(root) {
    if (!root || root.__inited) return;
    root.__inited = true;

    const wrapper = root.querySelector('.carousel-wrapper');
    const slides = Array.from(root.querySelectorAll('.carousel-slide'));
    const titles = Array.from(root.querySelectorAll('.carousel-title-item'));
    const btnPrev = root.querySelector('.carousel-prev');
    const btnNext = root.querySelector('.carousel-next');

    if (!wrapper || !slides.length) {
      root.style.display = 'none';
      return;
    }

    // 单张图隐藏按钮
    if (slides.length === 1) {
      root.classList.add('single');
    }

    // 标题索引与幻灯索引对齐
    titles.forEach((t, i) => {
      t.dataset.slide = String(i);
    });

    let index = 0;
    let timer = null;
    const autoplay = (root.getAttribute('data-autoplay') || '1') !== '0';
    const interval = Math.max(1500, parseInt(root.getAttribute('data-interval') || '4000', 10) || 4000);

    function update() {
      wrapper.style.transform = 'translateX(' + (-index * 100) + '%)';
      titles.forEach((t, i) => {
        if (i === index) t.classList.add('active');
        else t.classList.remove('active');

        const text = t.querySelector('.title-text');
        const ind = t.querySelector('.title-indicator');
        if (text) text.style.opacity = i === index ? '1' : '0.75';
        if (ind) ind.style.background = i === index ? '#ff6600' : 'transparent';
      });
    }

    function next() {
      index = (index + 1) % slides.length;
      update();
    }

    function prev() {
      index = (index - 1 + slides.length) % slides.length;
      update();
    }

    // 标题点击
    titles.forEach((t) => {
      t.addEventListener('click', function () {
        const i = parseInt(t.dataset.slide || '0', 10) || 0;
        index = Math.min(Math.max(i, 0), slides.length - 1);
        update();
        restartAutoplay();
      });
    });

    // 按钮点击
    if (btnPrev) {
      btnPrev.addEventListener('click', function () {
        prev();
        restartAutoplay();
      });
    }
    if (btnNext) {
      btnNext.addEventListener('click', function () {
        next();
        restartAutoplay();
      });
    }

    // 自动播放控制
    function startAutoplay() {
      if (!autoplay || slides.length <= 1) return;
      stopAutoplay();
      timer = setInterval(next, interval);
    }

    function stopAutoplay() {
      if (timer) {
        clearInterval(timer);
        timer = null;
      }
    }

    function restartAutoplay() {
      stopAutoplay();
      startAutoplay();
    }

    // 悬停/聚焦暂停
    root.addEventListener('mouseenter', stopAutoplay);
    root.addEventListener('mouseleave', startAutoplay);
    root.addEventListener('focusin', stopAutoplay);
    root.addEventListener('focusout', startAutoplay);

    // 触摸滑动
    let startX = 0;
    let curX = 0;
    let dragging = false;
    const threshold = 30;

    root.addEventListener(
      'touchstart',
      function (e) {
        if (!e.touches || !e.touches.length) return;
        startX = e.touches[0].clientX;
        curX = startX;
        dragging = true;
        root.classList.add('grabbing');
        stopAutoplay();
      },
      { passive: true }
    );

    root.addEventListener(
      'touchmove',
      function (e) {
        if (!dragging || !e.touches || !e.touches.length) return;
        curX = e.touches[0].clientX;
        const dx = curX - startX;
        wrapper.style.transform = 'translateX(calc(' + (-index * 100) + '% + ' + dx + 'px))';
      },
      { passive: true }
    );

    root.addEventListener('touchend', function () {
      if (!dragging) return;
      const dx = curX - startX;
      root.classList.remove('grabbing');
      dragging = false;
      if (Math.abs(dx) > threshold) {
        if (dx < 0) next();
        else prev();
      } else {
        update();
      }
      startAutoplay();
    });

    // 鼠标拖动(可选)
    let mouseDown = false;
    let mStartX = 0;

    root.addEventListener('mousedown', function (e) {
      mouseDown = true;
      mStartX = e.clientX;
      root.classList.add('grab');
      stopAutoplay();
    });

    window.addEventListener('mouseup', function (e) {
      if (!mouseDown) return;
      const dx = e.clientX - mStartX;
      mouseDown = false;
      root.classList.remove('grab');
      if (Math.abs(dx) > threshold) {
        if (dx < 0) next();
        else prev();
      } else {
        update();
      }
      startAutoplay();
    });

    // 初始化
    update();
    startAutoplay();
  } // <- 确保此处仅关闭 initCarousel 函数

  function initAll(context) {
    const scope = context && context.querySelectorAll ? context : document;
    scope.querySelectorAll('.carousel-container').forEach(initCarousel);
  }

  // 初次加载
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', function () {
      initAll();
    });
  } else {
    initAll();
  }

  // 动态内容(如可视化编辑器或AJAX)再次初始化
  if (window.mw && mw.hook) {
    mw.hook('wikipage.content').add(function (content) {
      // content 可能是 jQuery 对象,也可能是原生节点
      if (content && content[0] && content.find) {
        // jQuery 对象
        content.find('.carousel-container').each(function () {
          initCarousel(this);
        });
      } else if (content && content.querySelectorAll) {
        // 原生节点
        initAll(content);
      } else {
        initAll();
      }
    });
  }
})();

/* 装备 */
$(function() {
    // 创建遮罩层
    if ($('.equipment-wrapper').length > 0 && $('#equipment-overlay').length === 0) {
        $('body').append('<div id="equipment-overlay" class="equipment-overlay"></div>');
    }
    
    // 点击装备卡片显示弹窗
    $(document).on('click', '.equipment-card', function(e) {
        e.stopPropagation();
        
        var equipName = $(this).attr('data-equipment');
        var level = $(this).attr('data-level');
        var popup = $(this).closest('.equipment-wrapper').find('.equipment-popup');
        
        if (popup.length > 0) {
            $('#equipment-overlay').fadeIn(200);
            popup.fadeIn(200);
        }
    });
    
    // 防止点击装备名称链接时触发其他事件
    $(document).on('click', '.equipment-name-link a', function(e) {
        e.stopPropagation();
        // 允许默认的链接跳转行为
    });
    
    // 点击关闭按钮关闭弹窗
    $(document).on('click', '.equipment-popup-close', function(e) {
        e.stopPropagation();
        $(this).parent('.equipment-popup').fadeOut(200);
        $('#equipment-overlay').fadeOut(200);
    });
    
    // 点击遮罩层关闭弹窗
    $(document).on('click', '#equipment-overlay', function() {
        $('.equipment-popup:visible').fadeOut(200);
        $(this).fadeOut(200);
    });
    
    // 点击弹窗内容不关闭
    $(document).on('click', '.equipment-popup', function(e) {
        e.stopPropagation();
    });
});