您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Shows the market price for items on the Inventory, Quick Stock, and your Shop pages using ItemDB
当前为
// ==UserScript== // @name Neopets Item Price Tooltip (ItemDB) // @namespace https://itemdb.com.br // @version 1.3.1 // @description Shows the market price for items on the Inventory, Quick Stock, and your Shop pages using ItemDB // @author FatalFlaw // @match *://www.neopets.com/quickstock.phtml* // @match *://www.neopets.com/inventory.phtml* // @match *://www.neopets.com/market.phtml* // @grant GM_xmlhttpRequest // @license MIT // @connect itemdb.com.br // @require https://code.jquery.com/jquery-3.6.0.min.js // ==/UserScript== (function () { 'use strict'; const intl = new Intl.NumberFormat(); // Function to fetch item price and calculate median function fetchItemPrice(itemName, callback) { const itemSlug = itemName.toLowerCase().replace(/\s+/g, '-'); const itemPageUrl = `https://itemdb.com.br/item/${itemSlug}`; GM_xmlhttpRequest({ method: 'GET', url: itemPageUrl, onload: function (res) { if (res.status !== 200) { return callback('Error Fetching Price'); } const parser = new DOMParser(); const doc = parser.parseFromString(res.responseText, 'text/html'); const priceCells = Array.from(doc.querySelectorAll('table tbody tr td:first-child')) .map(td => { const text = td.textContent.trim().replace(/,/g, '').replace(/[^\d]/g, ''); return parseInt(text, 10); }) .filter(n => !isNaN(n)); const recentPrices = priceCells.slice(0, 10); if (recentPrices.length === 0) { return callback('No Price Data'); } recentPrices.sort((a, b) => a - b); const mid = Math.floor(recentPrices.length / 2); const median = recentPrices.length % 2 === 0 ? Math.round((recentPrices[mid - 1] + recentPrices[mid]) / 2) : recentPrices[mid]; const priceText = `${intl.format(median)} NP${recentPrices.length < 10 ? '*' : ''}`; callback(priceText); }, onerror: function () { callback('Error Fetching Price'); } }); } // Function to show the tooltip function showTooltip(e, priceText) { const tooltip = $('<div class="price-tooltip"></div>') .text(priceText) .css({ position: 'absolute', top: e.pageY + 10 + 'px', left: e.pageX + 10 + 'px', padding: '5px', backgroundColor: 'rgba(0, 0, 0, 0.75)', color: 'white', borderRadius: '5px', fontSize: '12px', zIndex: 9999 }); $('body').append(tooltip); $(document).one('click', function () { tooltip.remove(); }); } // Highlight text and trigger price fetch let timeout; $(document).on('mouseup', function (e) { const selectedText = window.getSelection().toString().trim(); if (selectedText) { clearTimeout(timeout); timeout = setTimeout(function () { fetchItemPrice(selectedText, function (priceText) { showTooltip(e, priceText); }); }, 300); // Delay lookup by 300ms } }); })();