Completely moved the goProx object off the global scope.

This commit is contained in:
00Fjongl 2024-07-23 15:56:58 -05:00
parent e72c8141b0
commit 4effdb50be
2 changed files with 141 additions and 107 deletions

View file

@ -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 { try {
const rammerheadUrl = await window.goProx.rammerhead( // Send an artificial input to the omnibox. The omnibox will create
"example.com", // a proxy URL and leave it as the input value in response.
false 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); console.log("Generated Rammerhead URL:", rammerheadUrl);
results.rammerhead = rammerheadUrl ? rammerheadUrl : "failure"; results.rammerhead = rammerheadUrl ? rammerheadUrl : "failure";
} catch (e) { } catch (e) {
@ -211,7 +230,11 @@ xx xx
waitForWorker(); 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. // For the hacky URL test, use the URL page's EXACT title.
const website = { const website = {
path: "example.com", path: "example.com",
@ -219,10 +242,15 @@ xx xx
}; };
try { try {
const generatedUrl = window.goProx.ultraviolet( // Send an artificial input to the omnibox. The omnibox will create
website.path, // a proxy URL and leave it as the input value in response.
false 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); console.log("Generated Ultraviolet URL:", generatedUrl);
results[0].ultraviolet = generatedUrl ? generatedUrl : "failure"; results[0].ultraviolet = generatedUrl ? generatedUrl : "failure";

View file

@ -361,8 +361,8 @@ const RammerheadEncode = async baseUrl => {
* goProx.searx(); * goProx.searx();
*/ */
addEventListener("DOMContentLoaded", () => { addEventListener("DOMContentLoaded", () => {
// Object.freeze prevents goProx from being edited. // Object.freeze prevents goProx from accidentally being edited.
self.goProx = Object.freeze({ 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),
@ -412,15 +412,21 @@ addEventListener("DOMContentLoaded", () => {
// Handle the other menu buttons differently if there is no omnibox. Menus // Handle the other menu buttons differently if there is no omnibox. Menus
// which lack an omnibox likely use buttons as mere links. // 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](prUrl.value, mode)}
: mode => () => {goProx[type](mode)}, : mode => () => {goProx[type](mode)},
// Ultraviolet is currently incompatible with window mode. // Ultraviolet is currently incompatible with window mode.
searchMode = type === "ultraviolet" ? "stealth" : "window"; searchMode = type === "ultraviolet" ? "stealth" : "window";
if (prUrl) prUrl.addEventListener("keydown", e => { if (prUrl) prUrl.addEventListener("keydown", async e => {
if (e.code === "Enter") goProxMethod(searchMode)(); 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")); if (prGo1) prGo1.addEventListener("click", goProxMethod("window"));
@ -430,7 +436,6 @@ addEventListener("DOMContentLoaded", () => {
prSet("pr-uv", "ultraviolet"); prSet("pr-uv", "ultraviolet");
prSet("pr-rh", "rammerhead"); prSet("pr-rh", "rammerhead");
});
@ -510,7 +515,7 @@ addEventListener("DOMContentLoaded", () => {
const functionsList = [ const functionsList = [
() => goFrame(item.path), () => goFrame(item.path),
() => goFrame("/?eg&core=" + item.core + "&rom=" + item.rom), () => 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)); a.addEventListener("click", clickHandler(functionsList[Object.values(dirnames).indexOf(dir)], a));
@ -543,3 +548,4 @@ addEventListener("DOMContentLoaded", () => {
} }
} }
})(); })();
});