您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Logs combat events, adds Torn API data, and integrates a button into the dropdown menu
当前为
// ==UserScript== // @name Torn Combat Logger with Dropdown Menu Integration // @namespace http://torn.com/ // @version 1.9 // @description Logs combat events, adds Torn API data, and integrates a button into the dropdown menu // @author Quanna_Parker // @match https://www.torn.com/* // @grant none // ==/UserScript== (function() { 'use strict'; // Add your Torn API key here const apiKey = "1uqibTz8DL62KG27"; // Replace with your actual API key // Initialize an array to store combat logs let combatLogs = JSON.parse(localStorage.getItem("combatLogs")) || []; // Max number of logs before auto-cleanup const maxLogs = 100; // Function to fetch Torn user data function fetchTornUserData(userId) { const url = `https://api.torn.com/user/${userId}?selections=&key=${apiKey}`; fetch(url) .then(response => response.json()) .then(data => { console.log('Torn User Data:', data); }) .catch(error => console.error('Error fetching Torn data:', error)); } // Function to log combat events function logCombat(eventDetails) { const logEntry = { time: new Date().toLocaleString(), attacker: eventDetails.attacker, attackerId: eventDetails.attackerId, damage: eventDetails.damage, result: eventDetails.result, attackType: eventDetails.attackType, yourHealthBefore: eventDetails.yourHealthBefore, yourHealthAfter: eventDetails.yourHealthAfter }; combatLogs.push(logEntry); // Fetch attacker details from the Torn API fetchTornUserData(eventDetails.attackerId); // Auto-cleanup: Remove the oldest log if exceeding maxLogs if (combatLogs.length > maxLogs) { combatLogs.shift(); } localStorage.setItem("combatLogs", JSON.stringify(combatLogs)); console.log("Combat logged: ", logEntry); } // Function to create a pop-up to view combat logs 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'; // Close button 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); // Display combat logs 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; } // Function to add a combat log button to the settings menu in Torn PDA function addCombatLogsToMenu() { const settings = document.querySelector(".settings-menu > li > a:contains(Settings)"); if (settings) { console.log('Settings menu found, adding Combat Logs button...'); const combatLogsMenu = settings.parentNode.cloneNode(true); const combatLogsLink = combatLogsMenu.querySelector("a"); combatLogsLink.href = "#"; combatLogsLink.innerText = "Combat Logs"; combatLogsMenu.onclick = function() { viewLogs(); }; settings.parentNode.parentNode.insertBefore(combatLogsMenu, settings.parentNode.nextSibling); } else { console.log('Settings menu not found.'); } } // Initialize the script on page load window.onload = function() { addCombatLogsToMenu(); }; })();