// ==UserScript== // @name Fantastic Contraption FT Button // @namespace http://tampermonkey.net/ // @version 1.1 // @description Adds a button to launch the FT version with the same level/design ID // @author You // @match http://*.fantasticcontraption.com/* // @match https://*.fantasticcontraption.com/* // @grant none // ==/UserScript== (function() { 'use strict'; // Function to get URL parameter value function getQueryParamValue(param) { const urlParams = new URLSearchParams(window.location.search); return urlParams.get(param); } // Function to create the FT button function createFtButton() { const levelId = getQueryParamValue("levelId"); const designId = getQueryParamValue("designId"); // Only add button if there's a levelId or designId if (!levelId && !designId) { return; } let ftUrl = "https://ft.jtai.dev/"; const params = []; if (levelId) { params.push("levelId=" + levelId); } if (designId) { params.push("designId=" + designId); } if (params.length > 0) { ftUrl += "?" + params.join("&"); } // Create the button element const ftButton = document.createElement('a'); ftButton.href = ftUrl; ftButton.target = '_blank'; ftButton.textContent = 'Play in FT'; ftButton.style.marginLeft = '10px'; return ftButton; } // Function to insert the button function insertFtButton() { // Wait a bit for the document.write to execute setTimeout(() => { // Look for the div that contains the desktop launcher script const footerDivs = document.querySelectorAll('footer div'); for (let div of footerDivs) { const script = div.querySelector('script'); if (script && script.textContent.includes('registryLauncherUrl')) { const ftButton = createFtButton(); if (ftButton) { // Check if there's already content (Windows users will have desktop launcher) const hasContent = div.textContent.trim().length > 0; if (hasContent) { // Windows: add after desktop launcher with proper spacing let content = div.innerHTML; content = content.replace(/\s*$/, ''); // Remove trailing
div.innerHTML = content + '  ·   Play in FT'; } else { // Non-Windows: add the FT button as the only content div.innerHTML = 'Play in FT'; } } break; } } }, 100); } // Wait for the page to load, then insert the button if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', insertFtButton); } else { insertFtButton(); } })();