Torn Inventory Highlighter

Highlight specific items in Torn inventory based on their names and adjust text color for dark mode

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Torn Inventory Highlighter
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  Highlight specific items in Torn inventory based on their names and adjust text color for dark mode
// @author       Pampy
// @match        https://www.torn.com/item.php
// @grant        none
// @license      Pampas
// ==/UserScript==

(function() {
    'use strict';

    const itemsToHighlight = {
        'Can Goose Juice': 'red',
        'Can of Damp Valley': 'red',
        'Can of Crocozade': 'red',
        'Can of Munster': 'orange',
        'Can of Santa Shooters': 'orange',
        'Can of Red Cow': 'yellow',
        'Can of Rockstar Rudolph': 'yellow',
        'Can of Taurine Elite': 'green',
        'Can of X-MASS': 'green'
    };

    function isDarkMode() {
        const bodyBackgroundColor = window.getComputedStyle(document.body).backgroundColor;
        // Assuming dark mode if the background color is dark
        const rgb = bodyBackgroundColor.match(/\d+/g);
        const brightness = (0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]) / 255;
        return brightness < 0.5;
    }

    function highlightItems() {
        const itemElements = document.querySelectorAll('[data-sort]');
        console.log(`Found ${itemElements.length} items with data-sort attribute`);
        const textColor = isDarkMode() ? 'black' : 'black';
        const fontWeight = 'bold'; // Always bold
        itemElements.forEach(itemElement => {
            const itemName = itemElement.getAttribute('data-sort');
            console.log(`Item name: ${itemName}`);
            for (const [name, color] of Object.entries(itemsToHighlight)) {
                if (itemName.includes(name)) {
                    console.log(`Highlighting item: ${name} with color: ${color}`);
                    itemElement.style.backgroundColor = color;
                    itemElement.style.color = textColor;
                    itemElement.style.fontWeight = fontWeight;
                    itemElement.style.setProperty('background-color', color, 'important');
                    itemElement.style.setProperty('color', textColor, 'important');
                    itemElement.style.setProperty('font-weight', fontWeight, 'important');
                }
            }
        });
    }

    window.addEventListener('load', () => {
        setTimeout(highlightItems, 2000); // Delay by 2 seconds
    });

    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.addedNodes.length) {
                highlightItems();
            }
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();