function handleRedirect(url, tabId) { chrome.storage.local.get(["enabled", "autoRedirect"], (result) => { const enabled = result.enabled !== false; // default true const autoRedirect = result.autoRedirect !== false; // default true
autoRedirectCheckbox.addEventListener("change", () => { chrome.storage.local.set({ autoRedirect: autoRedirectCheckbox.checked }); }); turbowarp chrome extension
// Save settings enableCheckbox.addEventListener("change", () => { chrome.storage.local.set({ enabled: enableCheckbox.checked }); }); function handleRedirect(url, tabId) { chrome
if (enabled && autoRedirect) { // Prevent the page from fully loading before redirect document.body.style.backgroundColor = "#f9f9f9"; const message = document.createElement("div"); message.innerText = "Redirecting to TurboWarp..."; message.style.position = "fixed"; message.style.top = "20px"; message.style.left = "20px"; message.style.padding = "10px 20px"; message.style.backgroundColor = "#4c97ff"; message.style.color = "white"; message.style.fontFamily = "sans-serif"; message.style.borderRadius = "8px"; message.style.zIndex = "9999"; document.body.appendChild(message); } }); } <!DOCTYPE html> <html> <head> <style> body { width: 260px; padding: 15px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } h3 { margin: 0 0 10px 0; color: #4c97ff; } label { display: block; margin-bottom: 12px; cursor: pointer; } button { margin-top: 10px; width: 100%; padding: 8px; background: #4c97ff; color: white; border: none; border-radius: 5px; cursor: pointer; } button:hover { background: #2c6bcb; } .note { font-size: 12px; color: #666; margin-top: 12px; text-align: center; } </style> </head> <body> <h3>⚡ TurboWarp Redirect</h3> <label> <input type="checkbox" id="enableCheckbox" checked> Enable extension </label> <label> <input type="checkbox" id="autoRedirectCheckbox" checked> Auto-redirect to TurboWarp </label> <button id="openTurboWarp">Open current project in TurboWarp</button> <div class="note">Works on scratch.mit.edu/projects/*</div> <script src="popup.js"></script> </body> </html> 5. popup.js document.addEventListener("DOMContentLoaded", () => { const enableCheckbox = document.getElementById("enableCheckbox"); const autoRedirectCheckbox = document.getElementById("autoRedirectCheckbox"); const openButton = document.getElementById("openTurboWarp"); // Load saved settings chrome.storage.local.get(["enabled", "autoRedirect"], (result) => { enableCheckbox.checked = result.enabled !== false; autoRedirectCheckbox.checked = result.autoRedirect !== false; }); if (window
if (enabled && autoRedirect) { const projectIdMatch = url.match(/scratch\.mit\.edu\/projects\/(\d+)/); if (projectIdMatch) { const projectId = projectIdMatch[1]; const turboUrl = `https://turbowarp.org/${projectId}`; chrome.tabs.update(tabId, { url: turboUrl }); } } }); } // This runs on Scratch project pages before the page loads. // It can be used to show a notification or override behavior. if (window.location.href.includes("scratch.mit.edu/projects/")) { chrome.storage.local.get(["enabled", "autoRedirect"], (result) => { const enabled = result.enabled !== false; const autoRedirect = result.autoRedirect !== false;
You can copy this code into a new folder and load it as an unpacked Chrome extension. turboWarpExtension/ ├── manifest.json ├── background.js ├── content.js └── icon.png (optional) 1. manifest.json { "manifest_version": 3, "name": "TurboWarp Redirect", "version": "1.0", "description": "Automatically opens Scratch projects in TurboWarp for better performance and features.", "permissions": [ "webNavigation", "storage" ], "host_permissions": [ "https://scratch.mit.edu/*", "https://turbowarp.org/*" ], "background": { "service_worker": "background.js" }, "content_scripts": [ { "matches": ["https://scratch.mit.edu/projects/*"], "js": ["content.js"], "run_at": "document_start" } ], "action": { "default_popup": "popup.html", "default_title": "TurboWarp Redirect" }, "icons": { "128": "icon.png" } } 2. background.js // Listen for navigation to Scratch project pages chrome.webNavigation.onHistoryStateUpdated.addListener((details) => { if (details.url && details.url.includes("scratch.mit.edu/projects/")) { handleRedirect(details.url, details.tabId); } }); chrome.webNavigation.onCommitted.addListener((details) => { if (details.url && details.url.includes("scratch.mit.edu/projects/")) { handleRedirect(details.url, details.tabId); } });