GGn Inventory Prices

Show prices in GGn inventory

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         GGn Inventory Prices
// @namespace    https://gazellegames.net/
// @version      1.0
// @description  Show prices in GGn inventory
// @author       monkeys
// @license      MIT
// @match        https://gazellegames.net/user.php?*action=inventory*
// @icon         https://gazellegames.net/favicon.ico
// @homepage     https://greasyfork.org/en/scripts/554362-ggn-inventory-prices
// @grant        GM.getValue
// @grant        GM.setValue
// @grant        GM.deleteValue
// ==/UserScript==

(async function() {
  'use strict';
  var coins_img = document.createElement('img');
  coins_img.src = '/static/styles/game_room/images/icons/coins.png'
  const user_id = new URLSearchParams(location.search).get("userid");
  var api_key = await GM.getValue("api_key");

  if (!api_key) {
    if (!(api_key = prompt("Please enter an API key with the 'Items' permission to use this script.")?.trim())) {
      return;
    }
    GM.setValue("api_key", api_key);
  }

  const url = `https://gazellegames.net/api.php?request=items&type=inventory&include_info=true&userid=${user_id}`;
  const options = {
    method: "GET",
    mode: "same-origin",
    credentials: "omit",
    redirect: "error",
    referrerPolicy: "no-referrer",
    headers: {
      "X-API-Key": api_key
    }
  };
  var inventory = await (await fetch(url, options)).json();
  if (inventory.status !== "success") {
    if (inventory.status === 401) {
      GM.deleteValue("api_key");
    }
    return;
  }
  for (const item_obj of inventory.response) {
    var item = item_obj.item;
    var amount_elm = document.getElementById (`amount_${item.id}`);
    if (!amount_elm) { continue; }
    var costs_elm = document.createElement('p');
    costs_elm.innerText = `Cost: ${Number(item.gold).toLocaleString()}, Total Value: ${(item.gold * item_obj.amount).toLocaleString()}`;
    // TODO: Can't get this coins img to actually show up
    // costs_elm.appendChild(coins_img);

    var shop_elm = document.createElement('p');
    shop_elm.innerText = `${item.infStock ? 'In' : 'Not in'} shop`;
    amount_elm.parentNode.insertBefore(shop_elm, amount_elm.nextSibling);
    amount_elm.parentNode.insertBefore(costs_elm, amount_elm.nextSibling);
  }
})();