GC - Virtupets API library

A library for virtupets.net APIs.

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/512407/1463866/GC%20-%20Virtupets%20API%20library.js

const url = "https://virtupets.net";

async function setupClientID() {
    let clientID;
    try {
        clientID = await GM.getValue('ClientID');
        if (!clientID) {
            const id = crypto.randomUUID();
            await GM.setValue('ClientID', crypto.randomUUID());
            clientID = id;
        }
    } catch (error) {
        console.error(error, "Failed to setup client ID.", "setupClientID");
        clientID = "";
    }
    return clientID;
}

async function createPostRequest(apiVersion, body) {
    const clientID = await setupClientID();
    return {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            "Version": apiVersion,
            "ClientID": clientID
        },
        body: JSON.stringify(body),
    }
}

/* Expects items to be an array of item name strings. */
async function bulkShopWizardPrices(items) {
    const apiVersion = "0.1";
    const request = await createPostRequest(apiVersion, items);
    return fetch(`${url}/shop-prices/bulk`, request);
}