Pixel Shop+

Makes it easier to create new custom shops for Idle Pixel

目前为 2024-02-25 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/488260/1333313/Pixel%20Shop%2B.js

  1. // ==UserScript==
  2. // @name Pixel Shop+
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.0
  5. // @description Makes it easier to create new custom shops for Idle Pixel
  6. // @author Dounford
  7. // @license MIT
  8. // @match *://idle-pixel.com/login/play*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. /*newCoinFormat = {
  13. name:'testCoin',
  14. image:'https://raw.githubusercontent.com/Dounford-Felipe/DHP-Pets/main/images/goldenHeart.gif',
  15. value:2000
  16. }
  17. */
  18. //PixelShopPlus.newCoin(newCoinFormat)
  19.  
  20. //newShopFormat = PixelShopPlus.newShop('fish','testCoin')
  21.  
  22. /*newItemFormat = [{
  23. name:"blueCat",
  24. imageUrl:"https://raw.githubusercontent.com/Dounford-Felipe/DHP-Pets/main/images/blueCat.png",
  25. coin:"testCoin",
  26. price:1000,
  27. tooltipText:"<span class='color-primary'>Blue Cat</span><br /><br />This cute cat wants to be your friend",
  28. buyText:"Adopt this cat to be your friend",
  29. boughtText:"Charlie will forever love you",
  30. bought:false,
  31. callback: function(){IdlePixelPlus.plugins.test.bought(pirate)}
  32. }]*/
  33. //PixelShopPlus.newItems('fish',newItemFormat)
  34.  
  35. (function PixelShopPlus() {
  36. 'use strict';
  37. const PixelShopPlus = {
  38. shops: ['vanilla'],
  39. coins: {},
  40. items: {},
  41. initialize: function () {
  42. window.addEventListener('load', function () {
  43. PixelShopPlus.newModals();
  44. PixelShopPlus.newShopDivs();
  45. //PixelShopPlus.loadCoins();
  46. });
  47. },
  48. //Creates
  49. newModals: function () {
  50. let customShopModalDiv = `<div style="width: 100%; height: 100%; position: absolute;top:0px; display: none;" id="customShopModalParent">
  51. <div style="background-color: black;opacity: 0.7;width: 100%;height: 100%;position: absolute;" onclick="document.getElementById('customShopModalParent').style.display='none'"></div>
  52. <div class="modal-content" id="customShopModal" style="z-index: 11;position: sticky;right: 0px;left: 0px;margin-right: auto;margin-left: auto;width: 35%;border-radius: 5px;top: 100px;">
  53. <div class="modal-header">
  54. <h5 class="modal-title text-secondary">Purchase Item</h5>
  55. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" onclick="document.getElementById('customShopModalParent').style.display='none'"></button>
  56. <input type="hidden" id="customShopModalShop">
  57. <input type="hidden" id="customShopModalItem">
  58. </div>
  59. <div class="modal-body">
  60. <span>
  61. <center>
  62. <img id="customShopModalImage" style="height:100px" src="" title="balance">
  63. </center>
  64. <br>
  65. <br>
  66. </span>
  67. <div class="center" id="customShopModalText"></div>
  68. </div>
  69. <div class="modal-footer">
  70. <button onclick="document.getElementById('customShopModalParent').style.display='none'"><span class="font-pixel hover">Cancel</span></button>
  71. <button id="customShopModalBuy" class="background-primary" style=""><span class="font-pixel hover">Purchase</span></button>
  72. </div>
  73. </div>
  74. </div>`
  75. document.getElementById('content').insertAdjacentHTML('beforeend', customShopModalDiv);
  76. document.getElementById('customShopModalBuy').addEventListener('click', PixelShopPlus.buyItem);
  77. },
  78. //Adds the change shop button
  79. newShopDivs: function () {
  80. let shopButton = document.createElement('div');
  81. shopButton.id = "shopButtons";
  82. shopButton.style.cssText = "white-space: nowrap; overflow-x: auto;";
  83. shopButton.innerHTML = `<div id="vanilla-shop" onclick="PixelShopPlus.changeShopTabs('vanilla')" style="background-color: rgb(247, 122, 129); white-space: normal;" class="quest-tab-button hover">
  84. VANILLA SHOP
  85. </div>`
  86. let vanillaShop = document.createElement('div');
  87. vanillaShop.id = "vanillaShop";
  88. while (document.getElementById('panel-shop').firstChild) {
  89. vanillaShop.appendChild(document.getElementById('panel-shop').firstChild);
  90. }
  91. document.getElementById('panel-shop').appendChild(shopButton);
  92. document.getElementById('panel-shop').insertAdjacentHTML('beforeend', '<hr>');
  93. document.getElementById('panel-shop').appendChild(vanillaShop);
  94. },
  95. //Change which shop is shown
  96. changeShopTabs: function(value) {
  97. // Oculta todos os tabs e remove o destaque
  98. for (const shopId of PixelShopPlus.shops) {
  99. document.getElementById(shopId + 'Shop').style.display = "none";
  100. document.getElementById(shopId + '-shop').style.backgroundColor = "";
  101. }
  102.  
  103. document.getElementById(value + 'Shop').style.display = "";
  104. document.getElementById(value + '-shop').style.backgroundColor = "#f77a81";
  105. },
  106. //Register a new coin
  107. newCoin: function(coin) {
  108. if (typeof PixelShopPlus.coins[coin.name] == 'undefined') {
  109. PixelShopPlus.coins[coin.name] = {image:coin.image,value:coin.value}
  110. }
  111. },
  112. //Increase the value of a coin
  113. coinIncrease: function(coin,increase) {
  114. PixelShopPlus.coins[coin].value += increase
  115. if (document.querySelector('[coin-value="' + coin + '"]')) {
  116. let coinElements = document.querySelectorAll('[coin-value="' + coin + '"]');
  117. coinElements.forEach(function(coinElement) {
  118. coinElement.textContent = PixelShopPlus.coins[coin].value.toLocaleString("en-US");
  119. });
  120. }
  121. },
  122. //Decrease the value of a coin
  123. coinDecrease: function(coin,decrease) {
  124. PixelShopPlus.coins[coin].value -= decrease
  125. if (document.querySelector('[coin-value="' + coin + '"]')) {
  126. let coinElements = document.querySelectorAll('[coin-value="' + coin + '"]');
  127. coinElements.forEach(function(coinElement) {
  128. coinElement.textContent = PixelShopPlus.coins[coin].value.toLocaleString("en-US");
  129. });
  130. }
  131. },
  132. //Set the value of a coin
  133. coinSet: function(coin,setValue) {
  134. PixelShopPlus.coins[coin].value = setValue
  135. if (document.querySelector('[coin-value="' + coin + '"]')) {
  136. let coinElements = document.querySelectorAll('[coin-value="' + coin + '"]');
  137. coinElements.forEach(function(coinElement) {
  138. coinElement.textContent = PixelShopPlus.coins[coin].value.toLocaleString("en-US");
  139. });
  140. }
  141. },
  142. //Register a new shop
  143. newShop: function (shop,coin) {
  144. PixelShopPlus.shops.push(shop);
  145. PixelShopPlus.items[shop] = {};
  146. let newTabButton = document.createElement('div');
  147. newTabButton.id = shop + "-shop";
  148. newTabButton.className = "quest-tab-button hover";
  149. newTabButton.style.marginLeft = "20px";
  150. newTabButton.innerHTML = shop.toLocaleUpperCase() + ' SHOP';
  151. newTabButton.onclick = function() {
  152. PixelShopPlus.changeShopTabs(shop);
  153. };
  154. document.getElementById('shopButtons').appendChild(newTabButton);
  155. let newShopPanel = document.createElement('div');
  156. newShopPanel.id = shop + "Shop"
  157. newShopPanel.style.display = "none"
  158. newShopPanel.innerHTML = `<h1>${shop.toLocaleUpperCase()} SHOP</h1>`
  159. if (typeof coin == 'string') {
  160. let newCoinImage = document.createElement('img');
  161. newCoinImage.src = PixelShopPlus.coins[coin].image
  162. newCoinImage.className = "w20"
  163. let newCoinValue = document.createElement('span');
  164. newCoinValue.setAttribute('coin-value', coin)
  165. newCoinValue.innerText = PixelShopPlus.coins[coin].value.toLocaleString("en-US")
  166. newShopPanel.appendChild(newCoinImage);
  167. newShopPanel.appendChild(newCoinValue);
  168. }
  169. newShopPanel.insertAdjacentHTML('beforeend', '<hr>');
  170. document.getElementById('panel-shop').appendChild(newShopPanel);
  171. },
  172. //Register an array of new buyable items
  173. newItems: function(shop,items) {
  174. items.forEach(function(item) {
  175. PixelShopPlus.items[shop][item.name] = item;
  176. if (item.bought == false) {
  177. let newShopItem = `<div id="shop-${item.name}" onclick="PixelShopPlus.openBuyModal('${shop}','${item.name}')" class="game-shop-box hover shadow" data-tooltip="shop-${item.name}" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-html="true" title="" data-bs-original-title="${item.tooltipText}">
  178. <div class="center mt-1">
  179. <img src="${item.imageUrl}" title="${item.name}" style="height: 50px;">
  180. </div>
  181. <div class="center mt-1">
  182. <img src="${PixelShopPlus.coins[item.coin].image}" title="${item.coin}" class="w20">
  183. <span id="${item.name}-shop-cost">${format_number(item.price)}</span>
  184. </div>
  185. </div>`
  186. document.getElementById(shop + 'Shop').insertAdjacentHTML('beforeend',newShopItem)
  187. $('#shop-' + item.name).tooltip()
  188. }
  189. })
  190. },
  191. //Open Buy Confirm
  192. openBuyModal: function(shop,item) {
  193. document.getElementById('customShopModalShop').value = shop;
  194. document.getElementById('customShopModalItem').value = item;
  195. document.getElementById('customShopModalImage').src = PixelShopPlus.items[shop][item].imageUrl;
  196. document.getElementById('customShopModalText').innerText = PixelShopPlus.items[shop][item].buyText;
  197. document.getElementById('customShopModalBuy').style.display='';
  198. document.getElementById('customShopModalParent').style.display='';
  199. },
  200. //Buy Item
  201. buyItem: function() {
  202. let shop = document.getElementById('customShopModalShop').value;
  203. let item = document.getElementById('customShopModalItem').value;
  204. let price = PixelShopPlus.items[shop][item].price
  205. let coin = PixelShopPlus.items[shop][item].coin;
  206. if (PixelShopPlus.coins[coin].value >= price) {
  207. PixelShopPlus.coinDecrease(coin,price);
  208. PixelShopPlus.items[shop][item].bought = true;
  209. document.getElementById('shop-' + item).style.display = "none";
  210. document.getElementById('customShopModalBuy').style.display="none";
  211. document.getElementById('customShopModalText').innerText = PixelShopPlus.items[shop][item].boughtText;
  212. if(PixelShopPlus.items[shop][item].callback !== "") {
  213. PixelShopPlus.items[shop][item].callback()
  214. }
  215. } else {
  216. document.getElementById('customShopModalBuy').style.display='none';
  217. document.getElementById('customShopModalText').innerText = "You can't afford this, sorry.";
  218. }
  219. },
  220. //Save the coin amount on localstorage
  221. saveCoins: function() {
  222. let key = `ShopPlus-${var_username}`;
  223. localStorage.setItem(key, JSON.stringify(PixelShopPlus.coins));
  224. },
  225. //Load the coin amount on localstorage
  226. loadCoins: function() {
  227. let key = `ShopPlus-${var_username}`;
  228. let loadedCoins = localStorage.getItem(key);
  229. if (loadedCoins) {
  230. PixelShopPlus.coins = JSON.parse(loadedCoins);
  231. }
  232. },
  233. };
  234. window.PixelShopPlus = PixelShopPlus;
  235. PixelShopPlus.initialize();
  236. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址