Last active
November 4, 2022 21:57
-
-
Save juvian/024135512b4dafc5ee9440efd095b48e to your computer and use it in GitHub Desktop.
UC Fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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