您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds an 'Open Chat' button on trade pages that works with Chat 3.0 and Torn PDA
// ==UserScript== // @name Torn Trade Page Chat Button // @namespace https://www.torn.com/ // @version 1.2 // @description Adds an 'Open Chat' button on trade pages that works with Chat 3.0 and Torn PDA // @author KillerCleat [2842410] // @match https://www.torn.com/trade.php* // @match https://www.torn.com/pda.php* // @grant none // @license MIT // @locale en-US // ==/UserScript== /** * Notes & Requirements: * – Author: KillerCleat [2842410] * – Description: Injects an 'Open Chat' button into any element starting with 'Trade Log' on PC and PDA trade pages. * – Works with Torn Chat 3.0 (PC) and Torn PDA chat interface. */ (function() { 'use strict'; /** Utility: Run callback when DOM is ready */ function onReady(fn) { if (document.readyState !== 'loading') { fn(); } else { document.addEventListener('DOMContentLoaded', fn); } } onReady(function() { // Locate the 'Trade Log' header element const header = Array.from(document.querySelectorAll('div,span')) .find(el => el.textContent.trim().startsWith('Trade Log')); if (!header) return; // Find the trade partner's user link (PC or PDA) const userLink = document.querySelector( 'a[href*="user.php?ID="], a[href*="pda.php?XID="]' ); if (!userLink) return; // Parse out the user ID const href = userLink.getAttribute('href'); const match = href.match(/[?&](?:ID|XID)=([0-9]+)/); if (!match) return; const userId = match[1]; // Create the 'Open Chat' button const btn = document.createElement('span'); btn.className = 'tt-open-chat'; btn.textContent = 'Open Chat'; btn.style.cursor = 'pointer'; btn.style.marginLeft = '10px'; btn.addEventListener('click', () => { const chatUrl = location.pathname.includes('pda.php') ? `/pda.php?chat=${userId}` : `/chat.php?user2=${userId}`; window.open(chatUrl, '_blank', 'width=400,height=600'); }); // Append the button if not already present const container = header.querySelector('div') || header; if (!container.querySelector('.tt-open-chat')) { container.appendChild(btn); } }); })();