Skip to content

Commit

Permalink
More code reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
00Fjongl committed Aug 9, 2024
1 parent 76bf532 commit fa018c4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 42 deletions.
60 changes: 26 additions & 34 deletions proxyServiceValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]);
Expand Down Expand Up @@ -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();
});
Expand Down
11 changes: 3 additions & 8 deletions views/assets/js/common-16451543478.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit fa018c4

Please sign in to comment.