// ==UserScript== // @name Neopets - Mark Collectable Cards Owned // @version 1.0.1 // @description Mark collectable cards owned (NeoDeck) // @author ikarus // @match *://www.neopets.com/games/neodeck/index.phtml* // @match *://*.neopets.com/inventory.phtml // @match *://*.neopets.com/objects.phtml?* // @match *://*.neopets.com/browseshop.phtml?* // @match *://*.neopets.com/safetydeposit.phtml* // @run-at document-end // @namespace https://greasyfork.org/users/1588069 // @downloadURL https://update.greasyfork.icu/scripts/572679/Neopets%20-%20Mark%20Collectable%20Cards%20Owned.user.js // @updateURL https://update.greasyfork.icu/scripts/572679/Neopets%20-%20Mark%20Collectable%20Cards%20Owned.meta.js // ==/UserScript== (function() { 'use strict'; const STORAGE_KEY = 'np_tcg_cards'; // ========================= // STORAGE // ========================= const cardsStorage = { get() { return JSON.parse(localStorage.getItem(STORAGE_KEY)) || { neodeck: [], tcg: [] }; }, set(data) { localStorage.setItem(STORAGE_KEY, JSON.stringify(data)); }, all() { const data = this.get(); return [...data.neodeck, ...data.tcg]; } }; // ========================= // NOME LIMPO // ========================= function cleanName(name) { return name.split('(')[0].trim(); } // ========================= // COLETA - NEODECK // ========================= function collectNeoDeck() { const data = cardsStorage.get(); const cards = []; document.querySelectorAll('b').forEach(el => { const name = cleanName(el.textContent); if (name.length > 2 && !cards.includes(name)) { cards.push(name); } }); data.neodeck = cards; cardsStorage.set(data); const info = document.createElement('div'); info.innerHTML = `TCG: ${cards.length} cartas registradas`; info.style.fontSize = '18px'; info.style.margin = '10px'; document.body.prepend(info); } // ========================= // MARCAR ITENS // ========================= function markCards(elements, table = false) { elements.each(function() { const el = $(this); const name = cleanName(el.text()); const isOwned = cardsStorage.all().includes(name); if (isOwned) { el.css('text-decoration', 'line-through'); el.parent().css('opacity', '50%'); if (table) { el.parent().parent().find('img').eq(0).css('opacity', '50%'); } } }); } // ========================= // PÁGINAS // ========================= const pages = [ { name: 'inventory', pageMatcher: /inventory/, itemNameObject: '.item-name' }, { name: 'neopian shop', pageMatcher: /type=shop/, itemNameObject: $('.item-name') }, { name: 'user shop', pageMatcher: /browseshop/, itemNameObject: $('a[href*=buy_item] + br + b') }, { name: 'sdb', pageMatcher: /safetydeposit/, itemNameObject: $('.content form>table').eq(1).find('tr:not(:first-child):not(:last-child) td:nth-child(2) > b'), table: true } ]; // ========================= // INIT // ========================= const url = window.location.href; if (url.includes('neodeck')) { collectNeoDeck(); } else if (localStorage.getItem(STORAGE_KEY)) { const page = pages.find(p => url.match(p.pageMatcher)); if (!page) return; if (page.name === 'inventory') { $(document).on('ajaxSuccess', () => { markCards($(page.itemNameObject)); }); } else { markCards(page.itemNameObject, page.table); } } })();