GC - Virtupets API library

A library for virtupets.net APIs.

נכון ליום 01-02-2025. ראה הגרסה האחרונה.

אין להתקין סקריפט זה ישירות. זוהי ספריה עבור סקריפטים אחרים // @require https://update.greatest.deepsurf.us/scripts/512407/1530419/GC%20-%20Virtupets%20API%20library.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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 createGetRequest(apiVersion) {
    const clientID = await setupClientID();
    return {
        method: "GET",
        headers: {
            "Version": apiVersion,
            "ClientID": 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),
    }
}

async function getItemDetails(itemName) {
    const apiVersion = "0.1";
    const request = await createGetRequest(apiVersion);
    return fetch(`${url}/items/details?q=${encodeURIComponent(itemName)}`, request);
}

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