mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-12 11:30:01 -04:00
Completely moved the goProx object off the global scope.
This commit is contained in:
parent
e72c8141b0
commit
4effdb50be
2 changed files with 141 additions and 107 deletions
|
@ -116,12 +116,31 @@ const testCommonJSOnPage = async () => {
|
|||
}
|
||||
});
|
||||
|
||||
if (window.goProx) {
|
||||
// Locate the omnibox element on the Rammerhead page.
|
||||
let omnibox = document.getElementById("pr-rh");
|
||||
omnibox = omnibox && omnibox.querySelector("input[type=text]");
|
||||
|
||||
if (omnibox) {
|
||||
try {
|
||||
const rammerheadUrl = await window.goProx.rammerhead(
|
||||
"example.com",
|
||||
false
|
||||
// Send an artificial input to the omnibox. The omnibox will create
|
||||
// a proxy URL and leave it as the input value in response.
|
||||
const urlPath = "example.com";
|
||||
omnibox.value = urlPath;
|
||||
await omnibox.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {code: "Validator Test"})
|
||||
);
|
||||
|
||||
// Wait up to 5 seconds for the omnibox to finish updating.
|
||||
const loadUrl = new Promise(resolve => {
|
||||
if (omnibox.value !== urlPath) resolve(omnibox.value);
|
||||
else omnibox.addEventListener("change", () => resolve(omnibox.value));
|
||||
}),
|
||||
timeout = new Promise(resolve => {
|
||||
setTimeout(() => resolve(omnibox.value), 5000);
|
||||
}),
|
||||
|
||||
// Record the proxy URL that the omnibox left here.
|
||||
rammerheadUrl = await Promise.race([loadUrl, timeout]);
|
||||
console.log("Generated Rammerhead URL:", rammerheadUrl);
|
||||
results.rammerhead = rammerheadUrl ? rammerheadUrl : "failure";
|
||||
} catch (e) {
|
||||
|
@ -211,7 +230,11 @@ xx xx
|
|||
waitForWorker();
|
||||
});
|
||||
|
||||
if (window.goProx && window.goProx.ultraviolet) {
|
||||
// Locate the omnibox element on the Ultraviolet page.
|
||||
let omnibox = document.getElementById("pr-uv");
|
||||
omnibox = omnibox && omnibox.querySelector("input[type=text]");
|
||||
|
||||
if (omnibox) {
|
||||
// For the hacky URL test, use the URL page's EXACT title.
|
||||
const website = {
|
||||
path: "example.com",
|
||||
|
@ -219,10 +242,15 @@ xx xx
|
|||
};
|
||||
|
||||
try {
|
||||
const generatedUrl = window.goProx.ultraviolet(
|
||||
website.path,
|
||||
false
|
||||
// Send an artificial input to the omnibox. The omnibox will create
|
||||
// a proxy URL and leave it as the input value in response.
|
||||
omnibox.value = website.path;
|
||||
await omnibox.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {code: "Validator Test"})
|
||||
);
|
||||
|
||||
// Record the proxy URL that the omnibox left here.
|
||||
const generatedUrl = omnibox.value;
|
||||
console.log("Generated Ultraviolet URL:", generatedUrl);
|
||||
results[0].ultraviolet = generatedUrl ? generatedUrl : "failure";
|
||||
|
||||
|
|
|
@ -361,8 +361,8 @@ const RammerheadEncode = async baseUrl => {
|
|||
* goProx.searx();
|
||||
*/
|
||||
addEventListener("DOMContentLoaded", () => {
|
||||
// Object.freeze prevents goProx from being edited.
|
||||
self.goProx = Object.freeze({
|
||||
// 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),
|
||||
|
@ -412,15 +412,21 @@ addEventListener("DOMContentLoaded", () => {
|
|||
|
||||
// Handle the other menu buttons differently if there is no omnibox. Menus
|
||||
// which lack an omnibox likely use buttons as mere links.
|
||||
const goProxMethod = prUrl !== undefined
|
||||
const goProxMethod = prUrl
|
||||
? mode => () => {goProx[type](prUrl.value, mode)}
|
||||
: mode => () => {goProx[type](mode)},
|
||||
|
||||
// Ultraviolet is currently incompatible with window mode.
|
||||
searchMode = type === "ultraviolet" ? "stealth" : "window";
|
||||
|
||||
if (prUrl) prUrl.addEventListener("keydown", e => {
|
||||
if (prUrl) prUrl.addEventListener("keydown", async e => {
|
||||
if (e.code === "Enter") goProxMethod(searchMode)();
|
||||
|
||||
// This is exclusively used for the validator script.
|
||||
else if (e.code === "Validator Test") {
|
||||
e.target.value = await goProx[type](e.target.value);
|
||||
e.target.dispatchEvent(new Event("change"));
|
||||
}
|
||||
});
|
||||
|
||||
if (prGo1) prGo1.addEventListener("click", goProxMethod("window"));
|
||||
|
@ -430,11 +436,10 @@ addEventListener("DOMContentLoaded", () => {
|
|||
|
||||
prSet("pr-uv", "ultraviolet");
|
||||
prSet("pr-rh", "rammerhead");
|
||||
});
|
||||
|
||||
|
||||
|
||||
(async () => {
|
||||
(async () => {
|
||||
// Load in relevant JSON files used to organize large sets of data.
|
||||
// This first one is for links, whereas the rest are for navigation menus.
|
||||
const huLinks = await fetch("/assets/json/links.json", {mode: "same-origin"}).then(response => response.json());
|
||||
|
@ -510,7 +515,7 @@ addEventListener("DOMContentLoaded", () => {
|
|||
const functionsList = [
|
||||
() => goFrame(item.path),
|
||||
() => goFrame("/?eg&core=" + item.core + "&rom=" + item.rom),
|
||||
() => item.custom ? goProx[item.custom]("stealth") : goFrame("/archive/g/" + item.path)
|
||||
item.custom ? () => goProx[item.custom]("stealth") : () => goFrame("/archive/g/" + item.path)
|
||||
];
|
||||
|
||||
a.addEventListener("click", clickHandler(functionsList[Object.values(dirnames).indexOf(dir)], a));
|
||||
|
@ -537,9 +542,10 @@ addEventListener("DOMContentLoaded", () => {
|
|||
}
|
||||
break;
|
||||
|
||||
// No default case.
|
||||
// No default case.
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
})();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue