From fa018c4993f17d32eb95668439aa1e4cb4656b16 Mon Sep 17 00:00:00 2001 From: 00Fjongl <65314359+00Fjongl@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:22:53 -0500 Subject: [PATCH] More code reformatting --- proxyServiceValidator.js | 60 ++++++++++++--------------- views/assets/js/common-16451543478.js | 11 ++--- 2 files changed, 29 insertions(+), 42 deletions(-) diff --git a/proxyServiceValidator.js b/proxyServiceValidator.js index 5cdadaa6..30afa724 100644 --- a/proxyServiceValidator.js +++ b/proxyServiceValidator.js @@ -111,15 +111,13 @@ const testCommonJSOnPage = async () => { const generateUrl = async (omniboxId, urlPath, errorPrefix = 'failure') => { // Wait for the document to load before getting the omnibox. await new Promise((resolve) => { - if (document.readyState === 'complete') { - resolve(); - } else { - window.addEventListener('load', resolve); - } + if (document.readyState === 'complete') resolve(); + else window.addEventListener('load', resolve); }); let omnibox = document.getElementById(omniboxId); omnibox = omnibox && omnibox.querySelector('input[type=text]'); + if (omnibox) { try { // Send an artificial input to the omnibox. The omnibox will create @@ -136,24 +134,18 @@ const testCommonJSOnPage = async () => { * not finished executing its script to listen for artificial inputs. */ await generateInput(); - const inputInterval = setInterval(generateInput, 5000); - - // Wait up to 40 seconds for the omnibox to finish updating. - const loadUrl = new Promise((resolve) => { - if (omnibox.value !== urlPath) { - clearInterval(inputInterval); - resolve(omnibox.value); - } else - omnibox.addEventListener('change', () => { - clearInterval(inputInterval); - resolve(omnibox.value); - }); + const inputInterval = setInterval(generateInput, 5000), + resolveHandler = (resolve) => () => { + clearInterval(inputInterval); + resolve(omnibox.value); + }, + // Wait up to 40 seconds for the omnibox to finish updating. + loadUrl = new Promise((resolve) => { + if (omnibox.value !== urlPath) resolveHandler(resolve)(); + else omnibox.addEventListener('change', resolveHandler(resolve)); }), timeout = new Promise((resolve) => { - setTimeout(() => { - clearInterval(inputInterval); - resolve(omnibox.value); - }, 40000); + setTimeout(resolveHandler(resolve), 40000); }), // Return the proxy URL that the omnibox left here. generatedUrl = await Promise.race([loadUrl, timeout]); @@ -247,19 +239,19 @@ xx xx const results = [{}, {}]; await new Promise((resolve) => { - const waitForDocument = () => - document.readyState === 'complete' - ? resolve() - : window.addEventListener('load', resolve); - - // Wait until a service worker is registered before continuing. - // Also check again to make sure the document is loaded. - const waitForWorker = async () => - setTimeout(async () => { - (await navigator.serviceWorker.getRegistrations()).length >= 1 - ? waitForDocument() - : waitForWorker(); - }, 1000); + const waitForDocument = () => { + if (document.readyState === 'complete') resolve(); + else window.addEventListener('load', resolve); + }, + // Wait until a service worker is registered before continuing. + // Also check again to make sure the document is loaded. + waitForWorker = async () => { + setTimeout(async () => { + (await navigator.serviceWorker.getRegistrations()).length > 0 + ? waitForDocument() + : waitForWorker(); + }, 1000); + }; waitForWorker(); }); diff --git a/views/assets/js/common-16451543478.js b/views/assets/js/common-16451543478.js index 329903b4..4d03783a 100644 --- a/views/assets/js/common-16451543478.js +++ b/views/assets/js/common-16451543478.js @@ -352,7 +352,8 @@ const RammerheadEncode = async (baseUrl) => { * goProx.searx(); */ addEventListener('DOMContentLoaded', async () => { - const goProx = { + // Object.freeze prevents goProx from accidentally being edited. + const goProx = Object.freeze({ // `location.protocol + "//" + getDomain()` more like `location.origin` // setAuthCookie("__cor_auth=1", false); ultraviolet: urlHandler(uvUrl), @@ -400,14 +401,8 @@ addEventListener('DOMContentLoaded', async () => { youtube: urlHandler(uvUrl('https://youtube.com')), discordUV: urlHandler(uvUrl('https://discord.com/app')), - }; - - // Don't slow down the rest of the script while encoding the URL. - RammerheadEncode('https://discord.com/app').then((url) => { - goProx.discordRH = urlHandler(url); - // Object.freeze prevents goProx from accidentally being edited. - Object.freeze(goProx); + discordRH: urlHandler(await RammerheadEncode('https://discord.com/app')), }); // Attach event listeners using goProx to specific app menus that need it.