mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-12 11:30:01 -04:00
More code reformatting
This commit is contained in:
parent
76bf532a6f
commit
fa018c4993
2 changed files with 29 additions and 42 deletions
|
@ -111,15 +111,13 @@ const testCommonJSOnPage = async () => {
|
||||||
const generateUrl = async (omniboxId, urlPath, errorPrefix = 'failure') => {
|
const generateUrl = async (omniboxId, urlPath, errorPrefix = 'failure') => {
|
||||||
// Wait for the document to load before getting the omnibox.
|
// Wait for the document to load before getting the omnibox.
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
if (document.readyState === 'complete') {
|
if (document.readyState === 'complete') resolve();
|
||||||
resolve();
|
else window.addEventListener('load', resolve);
|
||||||
} else {
|
|
||||||
window.addEventListener('load', resolve);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let omnibox = document.getElementById(omniboxId);
|
let omnibox = document.getElementById(omniboxId);
|
||||||
omnibox = omnibox && omnibox.querySelector('input[type=text]');
|
omnibox = omnibox && omnibox.querySelector('input[type=text]');
|
||||||
|
|
||||||
if (omnibox) {
|
if (omnibox) {
|
||||||
try {
|
try {
|
||||||
// Send an artificial input to the omnibox. The omnibox will create
|
// 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.
|
* not finished executing its script to listen for artificial inputs.
|
||||||
*/
|
*/
|
||||||
await generateInput();
|
await generateInput();
|
||||||
const inputInterval = setInterval(generateInput, 5000);
|
const inputInterval = setInterval(generateInput, 5000),
|
||||||
|
resolveHandler = (resolve) => () => {
|
||||||
// Wait up to 40 seconds for the omnibox to finish updating.
|
clearInterval(inputInterval);
|
||||||
const loadUrl = new Promise((resolve) => {
|
resolve(omnibox.value);
|
||||||
if (omnibox.value !== urlPath) {
|
},
|
||||||
clearInterval(inputInterval);
|
// Wait up to 40 seconds for the omnibox to finish updating.
|
||||||
resolve(omnibox.value);
|
loadUrl = new Promise((resolve) => {
|
||||||
} else
|
if (omnibox.value !== urlPath) resolveHandler(resolve)();
|
||||||
omnibox.addEventListener('change', () => {
|
else omnibox.addEventListener('change', resolveHandler(resolve));
|
||||||
clearInterval(inputInterval);
|
|
||||||
resolve(omnibox.value);
|
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
timeout = new Promise((resolve) => {
|
timeout = new Promise((resolve) => {
|
||||||
setTimeout(() => {
|
setTimeout(resolveHandler(resolve), 40000);
|
||||||
clearInterval(inputInterval);
|
|
||||||
resolve(omnibox.value);
|
|
||||||
}, 40000);
|
|
||||||
}),
|
}),
|
||||||
// Return the proxy URL that the omnibox left here.
|
// Return the proxy URL that the omnibox left here.
|
||||||
generatedUrl = await Promise.race([loadUrl, timeout]);
|
generatedUrl = await Promise.race([loadUrl, timeout]);
|
||||||
|
@ -247,19 +239,19 @@ xx xx
|
||||||
const results = [{}, {}];
|
const results = [{}, {}];
|
||||||
|
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
const waitForDocument = () =>
|
const waitForDocument = () => {
|
||||||
document.readyState === 'complete'
|
if (document.readyState === 'complete') resolve();
|
||||||
? resolve()
|
else window.addEventListener('load', resolve);
|
||||||
: window.addEventListener('load', resolve);
|
},
|
||||||
|
// Wait until a service worker is registered before continuing.
|
||||||
// Wait until a service worker is registered before continuing.
|
// Also check again to make sure the document is loaded.
|
||||||
// Also check again to make sure the document is loaded.
|
waitForWorker = async () => {
|
||||||
const waitForWorker = async () =>
|
setTimeout(async () => {
|
||||||
setTimeout(async () => {
|
(await navigator.serviceWorker.getRegistrations()).length > 0
|
||||||
(await navigator.serviceWorker.getRegistrations()).length >= 1
|
? waitForDocument()
|
||||||
? waitForDocument()
|
: waitForWorker();
|
||||||
: waitForWorker();
|
}, 1000);
|
||||||
}, 1000);
|
};
|
||||||
|
|
||||||
waitForWorker();
|
waitForWorker();
|
||||||
});
|
});
|
||||||
|
|
|
@ -352,7 +352,8 @@ const RammerheadEncode = async (baseUrl) => {
|
||||||
* goProx.searx();
|
* goProx.searx();
|
||||||
*/
|
*/
|
||||||
addEventListener('DOMContentLoaded', async () => {
|
addEventListener('DOMContentLoaded', async () => {
|
||||||
const goProx = {
|
// Object.freeze prevents goProx from accidentally being edited.
|
||||||
|
const goProx = Object.freeze({
|
||||||
// `location.protocol + "//" + getDomain()` more like `location.origin`
|
// `location.protocol + "//" + getDomain()` more like `location.origin`
|
||||||
// setAuthCookie("__cor_auth=1", false);
|
// setAuthCookie("__cor_auth=1", false);
|
||||||
ultraviolet: urlHandler(uvUrl),
|
ultraviolet: urlHandler(uvUrl),
|
||||||
|
@ -400,14 +401,8 @@ addEventListener('DOMContentLoaded', async () => {
|
||||||
youtube: urlHandler(uvUrl('https://youtube.com')),
|
youtube: urlHandler(uvUrl('https://youtube.com')),
|
||||||
|
|
||||||
discordUV: urlHandler(uvUrl('https://discord.com/app')),
|
discordUV: urlHandler(uvUrl('https://discord.com/app')),
|
||||||
};
|
|
||||||
|
|
||||||
// Don't slow down the rest of the script while encoding the URL.
|
discordRH: urlHandler(await RammerheadEncode('https://discord.com/app')),
|
||||||
RammerheadEncode('https://discord.com/app').then((url) => {
|
|
||||||
goProx.discordRH = urlHandler(url);
|
|
||||||
|
|
||||||
// Object.freeze prevents goProx from accidentally being edited.
|
|
||||||
Object.freeze(goProx);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Attach event listeners using goProx to specific app menus that need it.
|
// Attach event listeners using goProx to specific app menus that need it.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue