Originally Posted by
Bunnii
would it be even possible to have a script that is able to show you if something is already in your gallery from your inventory?
Here is the script:
Code:
// ==UserScript==
// @name Neopets: Inventory Gallery Checker
// @description Check the items in your inventory to see if they are in you gallery. Puts a G on the items that are in your gallery
// @author OneTwo
// @version 1.0
// @grant GM_xmlhttpRequest
// @match https://www.neopets.com/inventory.phtml
// ==/UserScript==
var appInsightsUserName;
// Find all script elements on the page
var scripts = document.querySelectorAll("script");
// Loop through each script element
scripts.forEach(function(script) {
// Check if the script contains the users username
if (script.textContent.includes("var appInsightsUserName")) {
// Extract the value of appInsightsUserName from the script
var startIndex = script.textContent.indexOf("'") + 1;
var endIndex = script.textContent.indexOf("'", startIndex);
appInsightsUserName = script.textContent.substring(startIndex, endIndex);
return;
}
});
// Construct the URL
var targetPageUrl = "https://www.neopets.com/gallery/index.phtml?" + appInsightsUserName
var galleryItems = [];
(function() {
'use strict';
// Fetch the target page
fetch(targetPageUrl)
.then(response => response.text())
.then(html => {
// Create a temporary element to parse the HTML
const tempElement = document.createElement('div');
tempElement.innerHTML = html;
// Find the form element
const formElement = tempElement.querySelector('form#gallery_form');
// Check if the form element exists
if (formElement) {
// Find the table element within the form
const tableElement = formElement.querySelector('table');
// Check if the table element exists
if (tableElement) {
// Find all item names in the gallery
galleryItems = Array.from(tableElement.querySelectorAll('b.textcolor')).map(item => item.innerText);
console.log('Extracted item names from the gallery:', galleryItems);
// Start checking for the inventory items
checkForInventoryItems();
} else {
console.log('Table element not found within the form');
}
} else {
console.log('Form element not found');
}
})
.catch(error => console.error('Error fetching page:', error));
})();
function checkForInventoryItems() {
// Select the inv grid element using its class name
var grid = document.querySelector(".itemgrid7__2020.item-grid");
// Check if the grid element is found
if (grid) {
// Get all the items within the grid
var invItems = grid.querySelectorAll(".grid-item");
// Loop through each item in the inventory
invItems.forEach(function(item) {
// Extract the name of the item
var itemName = item.querySelector(".item-name").textContent.trim();
// Check if the item is in the gallery
if (galleryItems.includes(itemName)) {
console.log("Item", itemName, "is in the gallery.");
// Add a green "G" with a white background next to the matching item in the grid
var markElement = document.createElement("div");
markElement.textContent = "G";
markElement.style.position = "absolute";
markElement.style.top = "0";
markElement.style.left = "0";
markElement.style.color = "green";
markElement.style.backgroundColor = "rgba(255, 255, 255, 0.5)"; // Adjust the alpha value as needed (0.0 to 1.0)
markElement.style.fontSize = "20px"; // Adjust the font size as needed
item.appendChild(markElement);
}
});
} else {
// If the grid element is not found, wait and then check again
setTimeout(checkForInventoryItems, 1000); // Check again after 1000ms
}
}