Torn Mini-profile Adds Xanax Consumption

Adds the number of Xanax a player has used when loading up the mini profile.

  1. // ==UserScript==
  2. // @name Torn Mini-profile Adds Xanax Consumption
  3. // @namespace TravisTheTechie
  4. // @version 2025.3
  5. // @description Adds the number of Xanax a player has used when loading up the mini profile.
  6. // @author Travis Smith
  7. // @match https://www.torn.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=torn.com
  9. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM.getValue
  13. // @grant GM.setValue
  14. // @grant GM_registerMenuCommand
  15. // @grant GM.registerMenuCommand
  16. // @license MIT
  17. // ==/UserScript==
  18. /* jshint esversion: 11 */
  19.  
  20. (async function() {
  21. 'use strict';
  22.  
  23. let apiKey = "";
  24. let shownConfig = false;
  25.  
  26.  
  27.  
  28. // Your code here...
  29. const observer = new MutationObserver(handleBodyUpdate);
  30. observer.observe(document, {
  31. childList: true,
  32. subtree: true
  33. });
  34.  
  35. let gmc = new GM_config({
  36. 'id': 'Torn-Mini-Profile-Xanax-Usage',
  37. 'title': 'Script Settings',
  38. 'fields':{
  39. 'ApiKey':{
  40. 'label': 'API Key (can be public)',
  41. 'type': 'text',
  42. 'default': ''
  43. }
  44. },
  45. 'events':{
  46. 'init': function () {
  47. apiKey = this.get("ApiKey");
  48. },
  49. 'save': function () {
  50. apiKey = this.get("ApiKey");
  51. }
  52. }
  53. });
  54.  
  55. GM_registerMenuCommand("Open Settings", function () { gmc.open(); });
  56.  
  57. async function handleBodyUpdate() {
  58. const profileDescriptionElement = document.querySelector("#profile-mini-root .description");
  59. if (!profileDescriptionElement) return;
  60. // tag already there, stop
  61. if (profileDescriptionElement.querySelector(".custom-xanax-taken")) return;
  62.  
  63. // find the userId
  64. const userImgElement = document.querySelector("#profile-mini-root div[class*=profile-mini-_userImageWrapper] a");
  65. if (!userImgElement) return;
  66. const userId = parseInt(userImgElement?.href?.replace(/\D/g, "")) || 0;
  67. if (!userId) return;
  68.  
  69. if (!apiKey) {
  70. if (!shownConfig) {
  71. gmc.open();
  72. shownConfig = true;
  73. }
  74. return;
  75. }
  76.  
  77. const url = `https://api.torn.com/user/${userId}?selections=personalstats&key=${apiKey}`
  78. const response = await fetch(url);
  79. const results = await response.json();
  80. const xanTaken = results?.personalstats?.xantaken;
  81. const eCansUsed = results?.personalstats?.energydrinkused;
  82. const eRefills = results?.personalstats?.refills;
  83. // no reason to show it if there's no data
  84. if (!xanTaken && !eCansUsed && !eRefills) return;
  85.  
  86. // tag already there, stop; gotta do it here since fetch is async
  87. if (profileDescriptionElement.querySelector(".custom-xanax-taken")) return;
  88.  
  89. const span = `<span class="custom-xanax-taken">Xanax Taken: ${xanTaken}, eCans Used: ${eCansUsed}, eRefills: ${eRefills}</span>`;
  90.  
  91. profileDescriptionElement.insertAdjacentHTML('beforeend', span);
  92. }
  93. })();

QingJ © 2025

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