// ==UserScript== // @name Pokechill 闪光果实插件 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 增加遗传道具闪光果实,使遗传闪光概率额外提高10% // @author 人民当家做主 // @match https://play-pokechill.github.io/* // @match https://g1tyx.github.io/play-pokechill/* // @icon https://play-pokechill.github.io/img/icons/icon.png // @grant none // ==/UserScript== (function() { 'use strict'; const SHINY_BERRY_IMAGE_URL = 'https://img.cdn1.vip/i/69b7c51d9eb97_1773651229.png'; const SHINY_BERRY_ID = 'shinyBerry'; function waitForGame() { if (typeof item === 'undefined' || typeof shop === 'undefined') { setTimeout(waitForGame, 100); return; } initPlugin(); } function initPlugin() { // 1. 添加新道具:闪光果实(中文介绍) if (!item[SHINY_BERRY_ID]) { item[SHINY_BERRY_ID] = { rename: '闪光果实', type: 'key', genetics: true, info: function() { return '遗传辅助道具:使遗传闪光的概率额外提高10%'; } }; item[SHINY_BERRY_ID].id = SHINY_BERRY_ID; } // 2. 添加商店商品(如需限制库存,请取消下一行的注释并设定库存数量) if (!shop.shopsShinyBerry) { shop.shopsShinyBerry = { icon: SHINY_BERRY_ID, name: '闪光果实', price: 20, currency: item.goldenBottleCap.id, category: 'genetics', // stock: 5, // 可选:设置库存数量,不设置则无限购买 }; } // 3. 修改遗传结束函数,增加闪光果实的额外10%概率判定 const originalSetGeneticMenu = window.setGeneticMenu; if (typeof originalSetGeneticMenu === 'function') { window.setGeneticMenu = function(mod, itemUsed) { let hostId = saved.geneticHost; originalSetGeneticMenu.call(this, mod, itemUsed); if (mod === 'end' && itemUsed === SHINY_BERRY_ID) { if (hostId && pkmn[hostId] && !pkmn[hostId].hidden && !pkmn[hostId].shiny) { if (Math.random() < 0.1) { pkmn[hostId].shiny = true; const tooltipMid = document.getElementById('tooltipMid'); if (tooltipMid) { const tags = tooltipMid.querySelector('.genetics-overview-tags'); const msg = '✦ 闪光突变 (闪光果实)!'; if (tags) { const div = document.createElement('div'); div.style.filter = 'hue-rotate(100deg)'; div.textContent = msg; tags.appendChild(div); } else { const extra = document.createElement('div'); extra.style.filter = 'hue-rotate(100deg)'; extra.textContent = msg; tooltipMid.appendChild(extra); } } } } } }; } // 4. 通用图片替换函数(适用于商店、背包、详情页) function replaceBerryImage(container) { const berryDivs = container.querySelectorAll('[data-item="' + SHINY_BERRY_ID + '"]'); berryDivs.forEach(div => { const img = div.querySelector('img'); if (img && img.src !== SHINY_BERRY_IMAGE_URL) { img.src = SHINY_BERRY_IMAGE_URL; img.style.objectFit = 'contain'; img.style.width = 'auto'; img.style.height = '2rem'; } }); } // 5. 监听商店列表 const shopObserver = new MutationObserver(() => { const shopListing = document.getElementById('shop-listing'); if (shopListing) replaceBerryImage(shopListing); }); const shopListing = document.getElementById('shop-listing'); if (shopListing) { shopObserver.observe(shopListing, { childList: true, subtree: true }); } // 6. 监听背包列表 const itemObserver = new MutationObserver(() => { const itemList = document.getElementById('item-menu-list'); if (itemList) replaceBerryImage(itemList); }); const itemList = document.getElementById('item-menu-list'); if (itemList) { itemObserver.observe(itemList, { childList: true, subtree: true }); } // 7. 修改 tooltipData 函数以显示自定义图片 const originalTooltipData = window.tooltipData; if (typeof originalTooltipData === 'function') { window.tooltipData = function(category, ttdata) { originalTooltipData.call(this, category, ttdata); if (category === 'item' && ttdata === SHINY_BERRY_ID) { setTimeout(() => { const tooltipTop = document.getElementById('tooltipTop'); if (tooltipTop) { const img = tooltipTop.querySelector('img'); if (img) { img.src = SHINY_BERRY_IMAGE_URL; img.style.objectFit = 'contain'; img.style.maxHeight = '7rem'; img.style.width = 'auto'; } } }, 50); } }; } console.log('闪光果实插件已加载!中文介绍已启用。'); } waitForGame(); })();