ftredirect.user.js
1// ==UserScript==
2// @name Fantastic Contraption FT Button
3// @namespace http://tampermonkey.net/
4// @version 1.1
5// @description Adds a button to launch the FT version with the same level/design ID
6// @author You
7// @match http://*.fantasticcontraption.com/*
8// @match https://*.fantasticcontraption.com/*
9// @grant none
10// ==/UserScript==
11
12(function() {
13 'use strict';
14
15 // Function to get URL parameter value
16 function getQueryParamValue(param) {
17 const urlParams = new URLSearchParams(window.location.search);
18 return urlParams.get(param);
19 }
20
21 // Function to create the FT button
22 function createFtButton() {
23 const levelId = getQueryParamValue("levelId");
24 const designId = getQueryParamValue("designId");
25
26 // Only add button if there's a levelId or designId
27 if (!levelId && !designId) {
28 return;
29 }
30
31 let ftUrl = "https://ft.jtai.dev/";
32 const params = [];
33
34 if (levelId) {
35 params.push("levelId=" + levelId);
36 }
37 if (designId) {
38 params.push("designId=" + designId);
39 }
40
41 if (params.length > 0) {
42 ftUrl += "?" + params.join("&");
43 }
44
45 // Create the button element
46 const ftButton = document.createElement('a');
47 ftButton.href = ftUrl;
48 ftButton.target = '_blank';
49 ftButton.textContent = 'Play in FT';
50 ftButton.style.marginLeft = '10px';
51
52 return ftButton;
53 }
54
55 // Function to insert the button
56 function insertFtButton() {
57 // Wait a bit for the document.write to execute
58 setTimeout(() => {
59 // Look for the div that contains the desktop launcher script
60 const footerDivs = document.querySelectorAll('footer div');
61
62 for (let div of footerDivs) {
63 const script = div.querySelector('script');
64 if (script && script.textContent.includes('registryLauncherUrl')) {
65 const ftButton = createFtButton();
66 if (ftButton) {
67 // Check if there's already content (Windows users will have desktop launcher)
68 const hasContent = div.textContent.trim().length > 0;
69
70 if (hasContent) {
71 // Windows: add after desktop launcher with proper spacing
72 let content = div.innerHTML;
73 content = content.replace(/<br\s*\/?>\s*$/, ''); // Remove trailing <br>
74 div.innerHTML = content + ' · <a href="' + ftButton.href + '" target="_blank">Play in FT</a>';
75 } else {
76 // Non-Windows: add the FT button as the only content
77 div.innerHTML = '<a href="' + ftButton.href + '" target="_blank">Play in FT</a>';
78 }
79 }
80 break;
81 }
82 }
83 }, 100);
84 }
85
86 // Wait for the page to load, then insert the button
87 if (document.readyState === 'loading') {
88 document.addEventListener('DOMContentLoaded', insertFtButton);
89 } else {
90 insertFtButton();
91 }
92
93})();