BazaarWatcher

Display total number of items and their value in the bazaar on the events page when the bazaar is open and you're in Hospital. Click to see item details sorted by price.

  1. // ==UserScript==
  2. // @name BazaarWatcher
  3. // @namespace https://github.com/0xymandias
  4. // @version 1.2
  5. // @description Display total number of items and their value in the bazaar on the events page when the bazaar is open and you're in Hospital. Click to see item details sorted by price.
  6. // @author smokey_ [2492729]
  7. // @match https://www.torn.com/page.php?sid=events
  8. // @grant GM_xmlhttpRequest
  9. // @connect api.torn.com
  10. // @license WTFPL
  11. // ==/UserScript==
  12.  
  13. // Copyright © 2034 smokey_ [2492729] <relatii@sri.ro,>
  14. // This work is free. You can redistribute it and/or modify it under the
  15. // terms of the Do What The Fuck You Want To Public License, Version 2,
  16. // as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
  17.  
  18. (function() {
  19. 'use strict';
  20.  
  21. // API Key and URLs
  22. const API_KEY = 'API_KEY_HERE';
  23. const BAZAAR_API_URL = `https://api.torn.com/user/?selections=bazaar&key=${API_KEY}`;
  24. const PROFILE_API_URL = `https://api.torn.com/user/?selections=profile&key=${API_KEY}&comment=SmokeysBazaarWatcher`;
  25.  
  26. // Function to fetch profile data from API
  27. function fetchProfileData() {
  28. GM_xmlhttpRequest({
  29. method: "GET",
  30. url: PROFILE_API_URL,
  31. onload: function(response) {
  32. if (response.status === 200) {
  33. const data = JSON.parse(response.responseText);
  34. if (data.basicicons && data.basicicons.icon35) {
  35. fetchBazaarData();
  36. }
  37. } else {
  38. console.error('Failed to fetch profile data');
  39. }
  40. }
  41. });
  42. }
  43.  
  44. // Function to fetch bazaar data from API
  45. function fetchBazaarData() {
  46. GM_xmlhttpRequest({
  47. method: "GET",
  48. url: BAZAAR_API_URL,
  49. onload: function(response) {
  50. if (response.status === 200) {
  51. const data = JSON.parse(response.responseText);
  52. displayBazaarInfo(data.bazaar);
  53. } else {
  54. console.error('Failed to fetch bazaar data');
  55. }
  56. }
  57. });
  58. }
  59.  
  60. // Function to display bazaar info
  61. function displayBazaarInfo(bazaarItems) {
  62. let totalItems = 0;
  63. let totalValue = 0;
  64.  
  65. bazaarItems.forEach(item => {
  66. totalItems += item.quantity;
  67. totalValue += item.price * item.quantity;
  68. });
  69.  
  70. const infoText = `Total Items in Bazaar: ${totalItems}, Total Value: $${totalValue.toLocaleString()}`;
  71.  
  72. // Create and style the info div
  73. const infoDiv = document.createElement('div');
  74. infoDiv.style.padding = '10px';
  75. infoDiv.style.backgroundColor = '#000';
  76. infoDiv.style.color = '#fff';
  77. infoDiv.style.marginBottom = '10px';
  78. infoDiv.style.fontSize = '16px';
  79. infoDiv.style.cursor = 'pointer';
  80. infoDiv.textContent = infoText;
  81.  
  82. // Create a table to display item details
  83. const tableDiv = document.createElement('div');
  84. tableDiv.style.display = 'none';
  85. tableDiv.style.position = 'absolute';
  86. tableDiv.style.top = '100px'; // Adjusted to fit below Torn Header
  87. tableDiv.style.left = '50px'; // Adjusted to center it between window edge and navigation panel
  88. tableDiv.style.backgroundColor = '#000';
  89. tableDiv.style.color = '#fff';
  90. tableDiv.style.padding = '10px';
  91. tableDiv.style.maxHeight = '80vh';
  92. tableDiv.style.overflowY = 'auto';
  93. tableDiv.style.zIndex = '1000';
  94.  
  95. const table = document.createElement('table');
  96. table.style.width = '100%';
  97. table.style.borderCollapse = 'collapse';
  98. table.style.color = '#fff';
  99.  
  100. const thead = document.createElement('thead');
  101. thead.innerHTML = `
  102. <tr style="background-color: #333;">
  103. <th style="border: 1px solid #555; padding: 8px;">Item Name</th>
  104. <th style="border: 1px solid #555; padding: 8px;">Quantity</th>
  105. <th style="border: 1px solid #555; padding: 8px;">Price</th>
  106. </tr>
  107. `;
  108. table.appendChild(thead);
  109.  
  110. const tbody = document.createElement('tbody');
  111. bazaarItems.sort((a, b) => b.price - a.price).forEach(item => {
  112. const row = document.createElement('tr');
  113. row.style.backgroundColor = '#222';
  114. row.innerHTML = `
  115. <td style="border: 1px solid #555; padding: 8px;">${item.name}</td>
  116. <td style="border: 1px solid #555; padding: 8px;">${item.quantity}</td>
  117. <td style="border: 1px solid #555; padding: 8px;">$${item.price.toLocaleString()}</td>
  118. `;
  119. tbody.appendChild(row);
  120. });
  121. table.appendChild(tbody);
  122. tableDiv.appendChild(table);
  123.  
  124. // Toggle the display of the table on info div click
  125. infoDiv.addEventListener('click', () => {
  126. tableDiv.style.display = tableDiv.style.display === 'none' ? 'block' : 'none';
  127. });
  128.  
  129. // Insert the info div and table div at the top of the page
  130. const container = document.querySelector('.titleContainer___QrlWP');
  131. if (container) {
  132. container.insertAdjacentElement('afterend', infoDiv);
  133. document.body.appendChild(tableDiv);
  134. } else {
  135. console.error('Container not found');
  136. }
  137. }
  138.  
  139. // Add custom CSS to make the text white
  140. const style = document.createElement('style');
  141. style.type = 'text/css';
  142. style.innerHTML = `
  143. body, td {
  144. color: #fff !important;
  145. }
  146. `;
  147. document.head.appendChild(style);
  148.  
  149. // Wait for the page to load fully before executing the script
  150. window.addEventListener('load', fetchProfileData);
  151. })();

QingJ © 2025

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