您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Sets your preferred pet as the first option when available
- // ==UserScript==
- // @name Neopets: Inventory Pet Preference
- // @namespace Nyu@Clraik
- // @version 1.0.0
- // @description Sets your preferred pet as the first option when available
- // @author Nyu
- // @match *://*.neopets.com/inventory.phtml
- // @icon https://www.google.com/s2/favicons?sz=64&domain=neopets.com
- // @license MIT
- // ==/UserScript==
- (async () => {
- const preferredPet = 'PETNAME' // YOUR PREFERED PET NAME HERE
- while (document.getElementById('invDesc').style.display === 'none') {
- await wait(1000)
- }
- await waitForLoadingToComplete()
- const items = Array.from(document.querySelectorAll('.grid-item'))
- for (const item of items) {
- item.addEventListener('click', async () => {
- await waitForLoadingToComplete()
- setPreferredPet()
- })
- }
- function setPreferredPet() {
- const select = document.querySelector('select[name="action"]')
- let petOption;
- for (let i = 0; i < select.options.length; i++) {
- if (select.options[i].value.includes(preferredPet)) {
- petOption = select.options[i]
- break
- }
- }
- if (petOption) {
- select.removeChild(petOption)
- select.insertBefore(petOption, select.options[1])
- }
- }
- async function waitForLoadingToComplete() {
- let isLoading = document.querySelector('.inv-loading-static')
- while (isLoading) {
- await wait(1000)
- isLoading = document.querySelector('.inv-loading-static')
- }
- }
- function wait(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- })()