Torn Combat Logger

Logger with repositioned Combat Logs button

目前為 2024-10-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Torn Combat Logger
// @namespace    http://torn.com/
// @version      2.9
// @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;
    }

    // Create and place the Combat Logs button back to its original position
    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'); // Or a different selector
    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);
})();