Torn Combat Logger

Combat Logger

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

// ==UserScript==
// @name         Torn Combat Logger
// @namespace    http://torn.com/
// @version      2.9
// @description  Combat Logger 
// @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
    const combatLogBtn = createButton('Combat Logs', 'combat-logs-btn', viewLogs);

    // Find the yellow settings button and append Combat Logs button below it
    const settingsBtn = document.querySelector('.icon-bell2');
    if (settingsBtn) {
        settingsBtn.parentNode.insertAdjacentElement('afterend', combatLogBtn);
    } else {
        console.error('Yellow settings button not found.');
    }

    // CSS for Combat Logs button: half size, better positioning
    const style = document.createElement('style');
    style.innerHTML = `
        .combat-logs-btn {
            padding: 5px;
            margin-top: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            width: 80px; /* Adjusted size */
            font-size: 10px;
            position: relative;
            z-index: 1000;
        }
    `;
    document.head.appendChild(style);
})();