Displaycase Value

Display the total value of items in the displaycase

  1. // ==UserScript==
  2. // @name Displaycase Value
  3. // @namespace com.torn.GamingAnonymous
  4. // @version 1.1
  5. // @description Display the total value of items in the displaycase
  6. // @author GamingAnonymous
  7. // @match *.torn.com/displaycase.php*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // Your API Key
  12. var apiKey = "yourAPIKey";
  13. var worthTotal = 0;
  14.  
  15. (function() {
  16. 'use strict';
  17. console.log("API Key: " + apiKey);
  18.  
  19. // get the ID of the displaycase you are currently viewing
  20. let currentPage = window.location.href;
  21. let urlElements = currentPage.split('/');
  22. let currentPageUserID = urlElements[urlElements.length - 1];
  23. console.log(currentPageUserID);
  24.  
  25. // Get the information from the API for this displaycase
  26. let url = 'https://api.torn.com/user/' + currentPageUserID + '?selections=display&key=' + apiKey;
  27. fetch(url)
  28. .then(res => res.json())
  29. .then((out) => {
  30. for(let i = 0; i < out.display.length; i++)
  31. {
  32. // Add up the worth of the items
  33. worthTotal += out.display[i].market_price;
  34. }
  35.  
  36. // Display the worth formatted with commas
  37. window.alert("This display case is worth: $" + worthTotal.toLocaleString(undefined));
  38. })
  39. .catch(err => console.error(err));
  40. })();