// ==UserScript== // @name 商店新增金色瓶盖兑换功能 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 在商店的每个页面顶部添加一个新商品,允许用5个银色瓶盖兑换1个金色瓶盖 // @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'; // 添加兑换商品到商店数据 shop.shopGoldenCrownExchange = { icon: item.goldenBottleCap.id, name: `金色王冠 x1`, price: 5, currency: item.bottleCap.id, category: `all`, // 在所有分类中显示 effect: function() { // 增加1个金色瓶盖 item.goldenBottleCap.got += 1; }, description: 'Exchange 5 Silver Crowns for 1 Golden Crown' }; // 修改updateItemShop函数,将兑换商品插入到顶部 const originalUpdateItemShop = updateItemShop; updateItemShop = function() { // 保存原始商店分类状态 const originalShopCategory = shopCategory; // 调用原始函数 originalUpdateItemShop.apply(this, arguments); // 如果当前在商店页面(分类已选定)且不在装饰或交换分类中 if (originalShopCategory !== undefined && originalShopCategory !== null && originalShopCategory !== 'decor' && originalShopCategory !== 'apricorn') { // 获取商店列表容器 const shopListing = document.getElementById("shop-listing"); if (shopListing) { // 查找现有的兑换商品,避免重复添加 let existingExchangeItem = document.querySelector('[data-exchange-item="goldenCrown"]'); if (!existingExchangeItem) { // 创建兑换商品元素 const exchangeDiv = document.createElement("div"); exchangeDiv.dataset.item = shop.shopGoldenCrownExchange.icon; exchangeDiv.dataset.exchangeItem = "goldenCrown"; // 标识这是兑换商品 // 使用与现有商品完全相同的HTML结构和样式 const shopItem = shop.shopGoldenCrownExchange.icon; const currency = shop.shopGoldenCrownExchange.currency || item.bottleCap.id; let name = format(shop.shopGoldenCrownExchange.icon); if (shop.shopGoldenCrownExchange.name) name = shop.shopGoldenCrownExchange.name; let stockTag = ""; // 生成与原代码完全相同的内容 let innerHTMLContent = ` ${name}${stockTag} x${shop.shopGoldenCrownExchange.price} `; exchangeDiv.innerHTML = innerHTMLContent; // 添加与原商品相同的点击事件 exchangeDiv.addEventListener("click", () => { document.getElementById("tooltipTop").style.display = "none" document.getElementById("tooltipTitle").innerHTML = "How many will you buy?" document.getElementById("tooltipMid").style.display = "none" document.getElementById("tooltipBottom").innerHTML = `
x1
x5
x10
x25
x50
x100
` document .querySelectorAll("#tooltipBottom div") .forEach(el => { el.addEventListener("click", () => { buyItem(+el.dataset.amount) }) }) openTooltip() }); // 购买功能 function buyItem(amount) { const currencyId = shop.shopGoldenCrownExchange.currency || item.bottleCap.id; const price = shop.shopGoldenCrownExchange.price; const totalCost = price * amount; if (item[currencyId].got >= totalCost) { // 扣除货币 item[currencyId].got -= totalCost; // 执行效果 for (let l = 0; l < amount; l++) { if (shop.shopGoldenCrownExchange.effect) { shop.shopGoldenCrownExchange.effect(); } else { item[shop.shopGoldenCrownExchange.icon].got += 1; } } updateItemShop(); closeTooltip(); } else { document.getElementById("tooltipTitle").innerHTML = "Cant afford"; document.getElementById("tooltipTop").style.display = "none"; document.getElementById("tooltipTop").style.display = "none"; document.getElementById("tooltipMid").style.display = "none"; document.getElementById("tooltipBottom").innerHTML = `You cant afford to purchase this`; } } // 将兑换商品插入到商店列表的顶部(在返回按钮之后,如果有返回按钮的话) const backButton = shopListing.querySelector('#shop-back'); if (backButton) { shopListing.insertBefore(exchangeDiv, backButton.nextSibling); } else { // 如果没有返回按钮,则插入到最前面 shopListing.insertBefore(exchangeDiv, shopListing.firstChild); } } } } }; // 页面加载完成后初始化 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function() { // 初始调用以确保在页面加载时也添加兑换商品 setTimeout(updateItemShop, 100); }); } else { // 如果页面已经加载完成 setTimeout(updateItemShop, 100); } })();