// ==UserScript== // @name 宝可梦挂机游戏 - 进化条件显示插件 // @namespace https://github.com/jinwind1/pokemon-idle // @version 1.0.0 // @description 在图鉴和队伍卡片中显示宝可梦的进化条件,优化显示长度,避免重复 // @author 人民当家做主 // @match https://jinwind1.github.io/pokemon-idle/ // @match https://jinwind1.github.io/pokemon-idle/* // @grant GM_addStyle // @run-at document-start // @license MIT // ==/UserScript== (function() { 'use strict'; // 添加进化信息样式 GM_addStyle(` .dex-evolution-section { margin-top: 8px; padding: 6px 8px; background: rgba(0, 0, 0, 0.2); border-radius: 6px; font-size: 11px; border-left: 3px solid #f39c12; } .dex-evolution-title { font-weight: bold; color: #f39c12; margin-bottom: 4px; } .dex-evolution-item { color: var(--text-secondary); margin-left: 8px; line-height: 1.4; } .team-evolution-info { font-size: 9px; color: #f39c12; background: rgba(243, 156, 18, 0.15); border-radius: 4px; padding: 1px 5px; margin-left: 6px; white-space: nowrap; display: inline-block; vertical-align: middle; cursor: help; } `); // 辅助函数:获取宝可梦的进化条件文本(HTML格式) function getEvolutionText(pokemonId) { const data = POKEMON_DATA[pokemonId]; if (!data) return ''; const evolvesTo = data.evolvesTo; if (!evolvesTo || (Array.isArray(evolvesTo) && evolvesTo.length === 0)) { // 最终形态:不显示任何进化区块(避免重复提示) return ''; } const evoList = Array.isArray(evolvesTo) ? evolvesTo : [evolvesTo]; let items = ''; for (const evo of evoList) { const targetName = POKEMON_DATA[evo.id]?.name || `#${evo.id}`; items += `
➜ Lv.${evo.level} 进化成 ${targetName}
`; } return `
🌱 进化条件
${items}
`; } // 辅助函数:获取队伍卡片中显示的进化徽章(简略版) function getTeamEvolutionBadge(pokemonId) { const data = POKEMON_DATA[pokemonId]; if (!data) return ''; const evolvesTo = data.evolvesTo; if (!evolvesTo || (Array.isArray(evolvesTo) && evolvesTo.length === 0)) { // 最终形态:不显示徽章 return ''; } const evoList = Array.isArray(evolvesTo) ? evolvesTo : [evolvesTo]; // 只显示最低进化等级,悬浮显示完整信息 let minLevel = Infinity; let targetName = ''; for (const evo of evoList) { if (evo.level < minLevel) { minLevel = evo.level; targetName = POKEMON_DATA[evo.id]?.name || `#${evo.id}`; } } if (minLevel === Infinity) return ''; // 仅显示等级,悬浮显示目标 return `🌱 Lv.${minLevel}`; } // 劫持 GameUI.prototype._renderPokedexBatch(分批渲染图鉴),在生成卡片后注入进化信息 const originalRenderBatch = GameUI.prototype._renderPokedexBatch; if (originalRenderBatch) { GameUI.prototype._renderPokedexBatch = function(grid, count) { originalRenderBatch.call(this, grid, count); // 为本次新增的卡片添加进化信息 const newCards = grid.querySelectorAll('.pokedex-entry:not([data-evo-injected])'); newCards.forEach(card => { const pokemonId = card.dataset.pokemonId; if (pokemonId) { const detailDiv = card.querySelector('.dex-detail'); if (detailDiv) { const evoHtml = getEvolutionText(parseInt(pokemonId)); if (evoHtml) { detailDiv.insertAdjacentHTML('beforeend', evoHtml); } } } card.setAttribute('data-evo-injected', 'true'); }); }; } else { // 降级方案:使用 MutationObserver(仅在劫持失败时使用) const observer = new MutationObserver(() => { document.querySelectorAll('.pokedex-entry:not([data-evo-injected])').forEach(card => { const pokemonId = card.dataset.pokemonId; if (pokemonId) { const detailDiv = card.querySelector('.dex-detail'); if (detailDiv) { const evoHtml = getEvolutionText(parseInt(pokemonId)); if (evoHtml) { detailDiv.insertAdjacentHTML('beforeend', evoHtml); } } } card.setAttribute('data-evo-injected', 'true'); }); }); observer.observe(document.getElementById('pokedex-grid'), { childList: true, subtree: true }); } // 劫持队伍渲染,添加进化徽章 const originalRenderTeam = GameUI.prototype.renderTeam; GameUI.prototype.renderTeam = function() { originalRenderTeam.call(this); const team = this.game.gameState.team; const slots = document.querySelectorAll('.team-slot'); for (let i = 0; i < slots.length && i < team.length; i++) { const pokemonId = team[i]; const evoBadge = getTeamEvolutionBadge(pokemonId); if (!evoBadge) continue; const slotNameDiv = slots[i].querySelector('.slot-name'); if (slotNameDiv && !slotNameDiv.querySelector('.team-evolution-info')) { slotNameDiv.insertAdjacentHTML('beforeend', evoBadge); } } }; // 初始执行:如果页面已加载,手动触发一次 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { setTimeout(() => { if (window.gameUI) { // 触发重新渲染以显示徽章 window.gameUI.renderTeam(); // 图鉴卡片可能已存在,手动处理 document.querySelectorAll('.pokedex-entry').forEach(card => { if (!card.hasAttribute('data-evo-injected')) { const pokemonId = card.dataset.pokemonId; if (pokemonId) { const detailDiv = card.querySelector('.dex-detail'); if (detailDiv) { const evoHtml = getEvolutionText(parseInt(pokemonId)); if (evoHtml) { detailDiv.insertAdjacentHTML('beforeend', evoHtml); } } } card.setAttribute('data-evo-injected', 'true'); } }); } }, 1000); }); } else { setTimeout(() => { if (window.gameUI) { window.gameUI.renderTeam(); document.querySelectorAll('.pokedex-entry').forEach(card => { if (!card.hasAttribute('data-evo-injected')) { const pokemonId = card.dataset.pokemonId; if (pokemonId) { const detailDiv = card.querySelector('.dex-detail'); if (detailDiv) { const evoHtml = getEvolutionText(parseInt(pokemonId)); if (evoHtml) { detailDiv.insertAdjacentHTML('beforeend', evoHtml); } } } card.setAttribute('data-evo-injected', 'true'); } }); } }, 1000); } })();