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와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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