item tracker

testsss

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/539070/1605553/item%20tracker.js

  1. Tabs.ItemTracker = {
  2. tabOrder: 920, // Place after Auto Porter Blocker tab
  3. tabLabel: 'Item Tracker',
  4. tabDisabled: false,
  5. myDiv: null,
  6. itemLog: [],
  7.  
  8. init: function(div) {
  9. var t = Tabs.ItemTracker;
  10. t.myDiv = div;
  11. t.createUI();
  12. t.hookInventory();
  13. t.loadItemLog();
  14. },
  15.  
  16. createUI: function() {
  17. var t = Tabs.ItemTracker;
  18. var m = '<DIV class=divHeader align=center>' + tx('Item Tracker') + '</div>';
  19.  
  20. m += '<div id="pbItemLog" style="width: 100%; height: 300px; overflow-y: auto; border: 1px solid #888; padding: 5px;"></div>';
  21. m += '<button id="pbClearItemLog">Clear Log</button>';
  22.  
  23. t.myDiv.innerHTML = m;
  24.  
  25. ById('pbClearItemLog').addEventListener('click', function() { t.clearItemLog(); });
  26. },
  27.  
  28. hookInventory: function() {
  29. var t = Tabs.ItemTracker;
  30. // This is a placeholder. You need to find the actual inventory element in the game.
  31. var inventoryElement = document.querySelector('#inventory_container'); // Replace with the correct selector
  32.  
  33. if (inventoryElement) {
  34. var observer = new MutationObserver(function(mutations) {
  35. mutations.forEach(function(mutation) {
  36. if (mutation.type === 'childList' || mutation.type === 'attributes') {
  37. // Check for changes that indicate item usage (e.g., removal from inventory)
  38. t.detectItemUsage(mutation);
  39. }
  40. });
  41. });
  42.  
  43. observer.observe(inventoryElement, {
  44. childList: true,
  45. subtree: true,
  46. attributes: true,
  47. attributeFilter: ['class'] // Example: track class changes
  48. });
  49. } else {
  50. console.error('Could not find inventory element. Update the selector in hookInventory().');
  51. }
  52. },
  53.  
  54. detectItemUsage: function(mutation) {
  55. var t = Tabs.ItemTracker;
  56. // This is a placeholder. You need to implement the logic to detect item usage based on the mutation.
  57. // Examine the mutation to determine if an item was used.
  58. // For example, check if a node was removed from the inventory or if an item's quantity changed.
  59.  
  60. if (mutation.removedNodes && mutation.removedNodes.length > 0) {
  61. mutation.removedNodes.forEach(function(node) {
  62. if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains('item')) { // Example: Check for removed item elements
  63. var itemName = node.textContent || node.innerText || ''; // Get the item name
  64. t.logItemUsage('Used item: ' + itemName);
  65. }
  66. });
  67. }
  68.  
  69. // Add more logic here to detect other types of item usage (e.g., quantity changes)
  70. },
  71.  
  72. logItemUsage: function(message) {
  73. var t = Tabs.ItemTracker;
  74. var timestamp = new Date().toLocaleString();
  75. var logEntry = '[' + timestamp + '] ' + message;
  76. t.itemLog.push(logEntry);
  77. t.updateItemLogDisplay();
  78. t.saveItemLog();
  79. },
  80.  
  81. updateItemLogDisplay: function() {
  82. var t = Tabs.ItemTracker;
  83. var logDiv = ById('pbItemLog');
  84. logDiv.innerHTML = ''; // Clear existing log
  85.  
  86. t.itemLog.forEach(function(logEntry) {
  87. var entryElement = document.createElement('div');
  88. entryElement.textContent = logEntry;
  89. logDiv.appendChild(entryElement);
  90. });
  91.  
  92. logDiv.scrollTop = logDiv.scrollHeight; // Scroll to bottom
  93. },
  94.  
  95. clearItemLog: function() {
  96. var t = Tabs.ItemTracker;
  97. t.itemLog = [];
  98. t.updateItemLogDisplay();
  99. t.saveItemLog();
  100. },
  101.  
  102. loadItemLog: function() {
  103. var t = Tabs.ItemTracker;
  104. var storedLog = localStorage.getItem('pbItemLog');
  105. if (storedLog) {
  106. t.itemLog = JSON.parse(storedLog);
  107. t.updateItemLogDisplay();
  108. }
  109. },
  110.  
  111. saveItemLog: function() {
  112. var t = Tabs.ItemTracker;
  113. localStorage.setItem('pbItemLog', JSON.stringify(t.itemLog));
  114. }
  115. };

QingJ © 2025

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