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);
}