// ==UserScript== // @name Trade History Button // @namespace http://tampermonkey.net/ // @version 1.2 // @description Adds a button that redirects you to previous trades with the user // @author You // @match https://www.chickensmoothie.com/trades/edittrade.php?* // @icon https://www.google.com/s2/favicons?sz=64&domain=chickensmoothie.com // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Get all elements with the class "header" const headers = document.getElementsByClassName("header"); // Ensure there are at least 2 headers if (headers.length < 2) { console.error("Not enough headers found."); return; } // Use header[1] if there are 3 headers, otherwise use header[0] const targetHeader = (headers.length === 3) ? headers[1] : headers[0]; const p = targetHeader.innerText; // Extract the username const x = p.slice(22, -1).trim(); // Encode the username to handle special characters like '+' const encodedUsername = encodeURIComponent(x); // Create the trade link const tradeLink = "https://www.chickensmoothie.com/trades/tradingcenter.php?partner=" + encodedUsername; // Create a button var btn = document.createElement("button"); btn.innerHTML = "Trade History"; // Prevent page reload and open the new window btn.onclick = (event) => { event.preventDefault(); // Prevent any default action of the button window.open(tradeLink); // Open the new window }; // Append the button at the end of the target header targetHeader.appendChild(btn); })();