GC - Virtupets API library

A library for virtupets.net APIs.

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/512407/1530419/GC%20-%20Virtupets%20API%20library.js

  1. const url = "https://virtupets.net";
  2. async function setupClientID() {
  3. let clientID;
  4. try {
  5. clientID = await GM.getValue('ClientID');
  6. if (!clientID) {
  7. const id = crypto.randomUUID();
  8. await GM.setValue('ClientID', crypto.randomUUID());
  9. clientID = id;
  10. }
  11. } catch (error) {
  12. console.error(error, "Failed to setup client ID.", "setupClientID");
  13. clientID = "";
  14. }
  15. return clientID;
  16. }
  17.  
  18. async function createGetRequest(apiVersion) {
  19. const clientID = await setupClientID();
  20. return {
  21. method: "GET",
  22. headers: {
  23. "Version": apiVersion,
  24. "ClientID": clientID
  25. }
  26. }
  27. }
  28.  
  29. async function createPostRequest(apiVersion, body) {
  30. const clientID = await setupClientID();
  31. return {
  32. method: "POST",
  33. headers: {
  34. "Content-Type": "application/json",
  35. "Version": apiVersion,
  36. "ClientID": clientID
  37. },
  38. body: JSON.stringify(body),
  39. }
  40. }
  41.  
  42. async function getItemDetails(itemName) {
  43. const apiVersion = "0.1";
  44. const request = await createGetRequest(apiVersion);
  45. return fetch(`${url}/items/details?q=${encodeURIComponent(itemName)}`, request);
  46. }
  47.  
  48. /* Expects items to be an array of item name strings. */
  49. async function bulkShopWizardPrices(items) {
  50. const apiVersion = "0.1";
  51. const request = await createPostRequest(apiVersion, items);
  52. return fetch(`${url}/shop-prices/bulk`, request);
  53. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址