TORN │ Better Chats

Slightly changes the appearance of chats on torn.com for the better.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         TORN │ Better Chats
// @namespace    http://tampermonkey.net/
// @version      1.4.42
// @description  Slightly changes the appearance of chats on torn.com for the better.
// @author       BOSSx [2718742]
// @match        https://www.torn.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function extractUserXID() {
        const xidElement = document.querySelector('.menu-value___gLaLR');
        if (xidElement) {
            const href = xidElement.getAttribute('href');
            if (href) {
                const xidMatch = href.match(/\/profiles.php\?XID=([A-Za-z0-9]+)/);
                if (xidMatch && xidMatch[1]) {
                    return xidMatch[1];
                }
            }
        }
        return null;
    }

    const myXID = extractUserXID();

    function styleLinksInsideChatContainers() {
        const containers = document.querySelectorAll('body');
        containers.forEach(container => {
            const links = container.querySelectorAll('._overview_1pskg_893 a, ._message_1pskg_509 a');
            links.forEach(link => {
                const href = link.getAttribute('href');
                if (href && href.includes('http')) {
                    link.style.color = '#66c2ff';
                    link.style.textDecoration = 'underline';
                } else if (href && href.includes('/profiles.php?XID=')) {
                    const xid = href.match(/XID=([A-Za-z0-9]+)/);
                    if (xid && xid[1]) {
                        if (xid[1] === myXID) {
                            link.style.color = '#80ff80';
                        } else {
                            link.style.color = '#ff4d4d';
                        }
                    }
                } else {
                    link.style.color = '#0099FF';
                    link.style.textDecoration = 'underline';
                }
            });
        });
    }

    function addMessageDividers() {
        const messageContainers = document.querySelectorAll('._message_1pskg_509');
        messageContainers.forEach(container => {
            container.style.borderTop = '1px solid #666';
            container.style.paddingTop = '5px';
        });
    }

    function addDiscordButtonToHeader() {
        const headerWrapperTop = document.querySelector('.header-wrapper-top');
        if (headerWrapperTop) {
            const discordContainer = document.createElement('div');
            discordContainer.style.position = 'absolute';
            discordContainer.style.top = '0';
            discordContainer.style.left = '5';
            discordContainer.style.zIndex = '9999';

            const discordButton = document.createElement('a');
            discordButton.href = 'https://discord.gg/N5xSNNRf8c';
            discordButton.target = '_blank';

            const discordImage = document.createElement('img');
            discordImage.src = 'https://cdn.discordapp.com/attachments/762927301108695141/1159242060348542996/discordtornlogo.png';
            discordImage.alt = 'Discord';
            discordImage.width = '72';
            discordImage.height = '72';

            discordButton.appendChild(discordImage);
            discordContainer.appendChild(discordButton);
            headerWrapperTop.appendChild(discordContainer);
        }
    }

    function checkForNewMessages() {
        styleLinksInsideChatContainers();
        addMessageDividers();
    }

    addDiscordButtonToHeader();
    setInterval(checkForNewMessages, 500);
})();