Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UC Fix
// ==UserScript==
// @name Neopets Fix UC Customization
// @namespace http://tampermonkey.net/
// @version 0.2
// @description After going to customization, make sure desired pet is selected and click on tampermonkey icon and then fixUC
// @author Juvian
// @match https://www.neopets.com/customise/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=neopets.com
// @require https://raw.githubusercontent.com/emilkm/amfjs/master/amf.js
// @grant GM_registerMenuCommand
// ==/UserScript==
function amfCall(client, cls, method, params) {
return new Promise((acc, rej) => {
client.invoke(cls, method, params).then(null, function(res) {
acc(res.detail.body);
})
});
}
async function fixUc(petname) {
if (petname[0].match(/[0-9]/)) {
const client = new amf.Client("amfphp", "https://www.neopets.com/amfphp/gateway.php");
const data = await amfCall(client, "CustomPetService", "getViewerData", [petname]);
const eqquiped = Object.fromEntries(Object.keys(data.custom_pet.equipped_by_zone).map(key => [key, data.custom_pet.equipped_by_zone[key].closet_obj_id]));
await amfCall(client, "CustomPetService", "saveChanges", [petname, data.custom_pet.slot]);
await amfCall(client, "CustomPetService", "saveChanges", [petname, data.custom_pet.slot, eqquiped]);
} else {
const data = await fetch("https://www.neopets.com/amfphp/json.php/CustomPetService.getViewerData/" + petname).then(r => r.json());
const eqquiped = Object.fromEntries(Object.keys(data.custom_pet.equipped_by_zone).map(key => [key, data.custom_pet.equipped_by_zone[key].closet_obj_id]));
await fetch(`https://www.neopets.com/amfphp/json.php/CustomPetService.saveChanges/${petname}/${data.custom_pet.slot}/`);
await fetch(`https://www.neopets.com/amfphp/json.php/CustomPetService.saveChanges/${petname}/${data.custom_pet.slot}/` + encodeURIComponent(JSON.stringify(eqquiped))).then(r => r.json()).then(console.log);
}
}
GM_registerMenuCommand('Fix UC', async function() {
const petname = document.querySelector('img.active_pet').title;
if (petname) await fixUc(petname);
alert('done');
}, 'r');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment