Skip to content

Instantly share code, notes, and snippets.

@juvian
Last active November 4, 2022 21:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juvian/024135512b4dafc5ee9440efd095b48e to your computer and use it in GitHub Desktop.
Save juvian/024135512b4dafc5ee9440efd095b48e to your computer and use it in GitHub Desktop.
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