Torn Combat Logger

Logger with repositioned Combat Logs button

נכון ליום 15-10-2024. ראה הגרסה האחרונה.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Torn Combat Logger
// @namespace    http://torn.com/
// @version      3.0
// @description  Logger with repositioned Combat Logs button
// @author       Quanna_Parker 
// @match        https://www.torn.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Torn API key
    const apiKey = "ADD_API_KEY"; // Replace with your actual API key

    // Combat logs storage
    let combatLogs = JSON.parse(localStorage.getItem("combatLogs")) || [];

    // Create the button element
    function createButton(text, className, onClickFunction) {
        const button = document.createElement('button');
        button.innerText = text;
        button.classList.add(className);
        button.addEventListener('click', onClickFunction);
        return button;
    }

    // Function to display logs in a window
    function viewLogs() {
        let logWindow = document.createElement('div');
        logWindow.style.position = 'fixed';
        logWindow.style.top = '50px';
        logWindow.style.right = '50px';
        logWindow.style.width = '400px';
        logWindow.style.height = '400px';
        logWindow.style.backgroundColor = 'white';
        logWindow.style.border = '1px solid black';
        logWindow.style.zIndex = 1000;
        logWindow.style.overflowY = 'scroll';
        logWindow.style.padding = '10px';
        logWindow.style.boxShadow = '0px 0px 10px rgba(0, 0, 0, 0.5)';
        logWindow.style.borderRadius = '10px';

        let closeButton = document.createElement('button');
        closeButton.innerHTML = 'Close';
        closeButton.style.float = 'right';
        closeButton.onclick = function() {
            document.body.removeChild(logWindow);
        };

        let logContent = document.createElement('div');
        logWindow.appendChild(closeButton);
        logWindow.appendChild(logContent);
        document.body.appendChild(logWindow);

        // Logs display
        let logsHTML = '<h3>Combat Logs</h3>';
        combatLogs.forEach(log => {
            logsHTML += `<p><strong>Time:</strong> ${log.time}<br/>
                         <strong>Attacker:</strong> ${log.attacker}<br/>
                         <strong>Damage:</strong> ${log.damage}<br/>
                         <strong>Result:</strong> ${log.result}<br/>
                         <strong>Attack Type:</strong> ${log.attackType}<br/>
                         <strong>Your Health (Before):</strong> ${log.yourHealthBefore}<br/>
                         <strong>Your Health (After):</strong> ${log.yourHealthAfter}</p><hr/>`;
        });
        logContent.innerHTML = logsHTML;
    }

    // Wait until the page is fully loaded
    window.addEventListener('load', function() {
        // Create and place the Combat Logs button
        const combatLogBtn = createButton('Combat Logs', 'combat-logs-btn', viewLogs);

        // Add it to the existing dropdown or a parent element
        const dropdownMenu = document.querySelector('.settings-menu'); // Adjust this selector if needed
        if (dropdownMenu) {
            dropdownMenu.appendChild(combatLogBtn);
        } else {
            console.error('Dropdown menu not found.');
        }

        // CSS for Combat Logs button
        const style = document.createElement('style');
        style.innerHTML = `
            .combat-logs-btn {
                padding: 5px;
                background-color: #4CAF50;
                color: white;
                border: none;
                border-radius: 5px;
                cursor: pointer;
                margin-top: 5px;
            }
        `;
        document.head.appendChild(style);
    });
})();