From 09a9cc4a372bd4de4f770cd7b09cf518017df09b Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Tue, 7 Jan 2025 02:07:27 -0500 Subject: [PATCH] Update TGBeta.ps1 --- TGBeta.ps1 | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/TGBeta.ps1 b/TGBeta.ps1 index 4188c2f..0ae2b83 100644 --- a/TGBeta.ps1 +++ b/TGBeta.ps1 @@ -912,13 +912,14 @@ function GetHtmlContent { }); - async function runSelectedTweaks() { + function runSelectedTweaks() { const tweaks = []; const tweakCheckboxes = document.querySelectorAll('#tweaksTab input[type="checkbox"]:not(#selectAllTweaksCheckbox)'); + // Collect the selected tweaks tweakCheckboxes.forEach((checkbox) => { if (checkbox.checked) { - tweaks.push(checkbox.id); // Use the checkbox IDs as tweak identifiers + tweaks.push(checkbox.id); // Use checkbox IDs as identifiers } }); @@ -929,25 +930,31 @@ function GetHtmlContent { appendLog("Running selected tweaks...", "yellow"); - try { - const response = await fetch('/runTweaks', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ tweaks }), - }); + // Prepare the payload + const payload = { tweaks }; + // Make the request using fetch with a promise-based approach + fetch('/runTweaks', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload), + }) + .then((response) => { if (!response.ok) { throw new Error('Failed to run selected tweaks. Please try again.'); } - - const result = await response.text(); + return response.text(); // Extract text response + }) + .then((result) => { appendLog(result, "green"); - } catch (error) { + }) + .catch((error) => { appendLog(`Error: ${error.message}`, "red"); - } + }); } + function appendLog(message, color = "white") { const log = document.createElement('p'); log.style.color = color;