GC - Virtupets API library

A library for virtupets.net APIs.

بۇ قوليازمىنى بىۋاسىتە قاچىلاشقا بولمايدۇ. بۇ باشقا قوليازمىلارنىڭ ئىشلىتىشى ئۈچۈن تەمىنلەنگەن ئامبار بولۇپ، ئىشلىتىش ئۈچۈن مېتا كۆرسەتمىسىگە قىستۇرىدىغان كود: // @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);
}