item tracker

testsss

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/539070/1605553/item%20tracker.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

Tabs.ItemTracker = {
    tabOrder: 920, // Place after Auto Porter Blocker tab
    tabLabel: 'Item Tracker',
    tabDisabled: false,
    myDiv: null,
    itemLog: [],

    init: function(div) {
        var t = Tabs.ItemTracker;
        t.myDiv = div;
        t.createUI();
        t.hookInventory();
        t.loadItemLog();
    },

    createUI: function() {
        var t = Tabs.ItemTracker;
        var m = '<DIV class=divHeader align=center>' + tx('Item Tracker') + '</div>';

        m += '<div id="pbItemLog" style="width: 100%; height: 300px; overflow-y: auto; border: 1px solid #888; padding: 5px;"></div>';
        m += '<button id="pbClearItemLog">Clear Log</button>';

        t.myDiv.innerHTML = m;

        ById('pbClearItemLog').addEventListener('click', function() { t.clearItemLog(); });
    },

    hookInventory: function() {
        var t = Tabs.ItemTracker;
        // This is a placeholder. You need to find the actual inventory element in the game.
        var inventoryElement = document.querySelector('#inventory_container'); // Replace with the correct selector

        if (inventoryElement) {
            var observer = new MutationObserver(function(mutations) {
                mutations.forEach(function(mutation) {
                    if (mutation.type === 'childList' || mutation.type === 'attributes') {
                        // Check for changes that indicate item usage (e.g., removal from inventory)
                        t.detectItemUsage(mutation);
                    }
                });
            });

            observer.observe(inventoryElement, {
                childList: true,
                subtree: true,
                attributes: true,
                attributeFilter: ['class'] // Example: track class changes
            });
        } else {
            console.error('Could not find inventory element.  Update the selector in hookInventory().');
        }
    },

    detectItemUsage: function(mutation) {
        var t = Tabs.ItemTracker;
        // This is a placeholder. You need to implement the logic to detect item usage based on the mutation.
        // Examine the mutation to determine if an item was used.
        // For example, check if a node was removed from the inventory or if an item's quantity changed.

        if (mutation.removedNodes && mutation.removedNodes.length > 0) {
            mutation.removedNodes.forEach(function(node) {
                if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains('item')) { // Example: Check for removed item elements
                    var itemName = node.textContent || node.innerText || ''; // Get the item name
                    t.logItemUsage('Used item: ' + itemName);
                }
            });
        }

        // Add more logic here to detect other types of item usage (e.g., quantity changes)
    },

    logItemUsage: function(message) {
        var t = Tabs.ItemTracker;
        var timestamp = new Date().toLocaleString();
        var logEntry = '[' + timestamp + '] ' + message;
        t.itemLog.push(logEntry);
        t.updateItemLogDisplay();
        t.saveItemLog();
    },

    updateItemLogDisplay: function() {
        var t = Tabs.ItemTracker;
        var logDiv = ById('pbItemLog');
        logDiv.innerHTML = ''; // Clear existing log

        t.itemLog.forEach(function(logEntry) {
            var entryElement = document.createElement('div');
            entryElement.textContent = logEntry;
            logDiv.appendChild(entryElement);
        });

        logDiv.scrollTop = logDiv.scrollHeight; // Scroll to bottom
    },

    clearItemLog: function() {
        var t = Tabs.ItemTracker;
        t.itemLog = [];
        t.updateItemLogDisplay();
        t.saveItemLog();
    },

    loadItemLog: function() {
        var t = Tabs.ItemTracker;
        var storedLog = localStorage.getItem('pbItemLog');
        if (storedLog) {
            t.itemLog = JSON.parse(storedLog);
            t.updateItemLogDisplay();
        }
    },

    saveItemLog: function() {
        var t = Tabs.ItemTracker;
        localStorage.setItem('pbItemLog', JSON.stringify(t.itemLog));
    }
};