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 {
|
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";
|
||||||
|
|
||||||
|
|
|
@ -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,116 +436,116 @@ addEventListener("DOMContentLoaded", () => {
|
||||||
|
|
||||||
prSet("pr-uv", "ultraviolet");
|
prSet("pr-uv", "ultraviolet");
|
||||||
prSet("pr-rh", "rammerhead");
|
prSet("pr-rh", "rammerhead");
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// Load in relevant JSON files used to organize large sets of data.
|
// 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.
|
// 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());
|
const huLinks = await fetch("/assets/json/links.json", {mode: "same-origin"}).then(response => response.json());
|
||||||
|
|
||||||
for (let item of Object.entries(huLinks))
|
for (let item of Object.entries(huLinks))
|
||||||
// Replace all placeholder links with the corresponding entry in huLinks.
|
// Replace all placeholder links with the corresponding entry in huLinks.
|
||||||
(document.getElementById(item[0]) || {}).href = item[1];
|
(document.getElementById(item[0]) || {}).href = item[1];
|
||||||
|
|
||||||
const navLists = {
|
const navLists = {
|
||||||
// Pair an element ID with a JSON file name. They are identical for now.
|
// Pair an element ID with a JSON file name. They are identical for now.
|
||||||
"emu-nav": "emu-nav",
|
"emu-nav": "emu-nav",
|
||||||
"emulib-nav": "emulib-nav",
|
"emulib-nav": "emulib-nav",
|
||||||
"flash-nav": "flash-nav",
|
"flash-nav": "flash-nav",
|
||||||
"h5-nav": "h5-nav"
|
"h5-nav": "h5-nav"
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let [listId, filename] of Object.entries(navLists)) {
|
for (let [listId, filename] of Object.entries(navLists)) {
|
||||||
|
|
||||||
let navList = document.getElementById(listId);
|
let navList = document.getElementById(listId);
|
||||||
|
|
||||||
if(navList) {
|
if(navList) {
|
||||||
// List items stored in JSON format will be returned as a JS object.
|
// List items stored in JSON format will be returned as a JS object.
|
||||||
const data = await fetch(`/assets/json/${filename}.json`, {mode: "same-origin"}).then(response => response.json());
|
const data = await fetch(`/assets/json/${filename}.json`, {mode: "same-origin"}).then(response => response.json());
|
||||||
|
|
||||||
// Load the JSON lists into specific HTML parent elements as groups of
|
// Load the JSON lists into specific HTML parent elements as groups of
|
||||||
// child elements, if the parent element is found.
|
// child elements, if the parent element is found.
|
||||||
switch (filename) {
|
switch (filename) {
|
||||||
case "emu-nav":
|
case "emu-nav":
|
||||||
case "emulib-nav":
|
case "emulib-nav":
|
||||||
case "h5-nav": {
|
case "h5-nav": {
|
||||||
const dirnames = {
|
const dirnames = {
|
||||||
// Set the directory of where each item of the corresponding JSON
|
// Set the directory of where each item of the corresponding JSON
|
||||||
// list will be retrieved from.
|
// list will be retrieved from.
|
||||||
"emu-nav": "emu",
|
"emu-nav": "emu",
|
||||||
"emulib-nav": "emulib",
|
"emulib-nav": "emulib",
|
||||||
"h5-nav": "h5g"
|
"h5-nav": "h5g"
|
||||||
},
|
},
|
||||||
|
|
||||||
dir = dirnames[filename],
|
dir = dirnames[filename],
|
||||||
|
|
||||||
// Add a little functionality for each list item when clicked on.
|
// Add a little functionality for each list item when clicked on.
|
||||||
clickHandler = (parser, a) => e => {
|
clickHandler = (parser, a) => e => {
|
||||||
if (e.target == a || e.target.tagName != "A") {
|
if (e.target == a || e.target.tagName != "A") {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
parser();
|
parser();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let item of data) {
|
||||||
|
// Load each item as an anchor tag with an image, heading,
|
||||||
|
// description, and click event listener.
|
||||||
|
let a = document.createElement("a");
|
||||||
|
a.href = "#";
|
||||||
|
|
||||||
|
let img = document.createElement("img");
|
||||||
|
img.src = `/assets/img/${dir}/` + item.img;
|
||||||
|
let title = document.createElement("h3");
|
||||||
|
title.textContent = item.name;
|
||||||
|
let desc = document.createElement("p");
|
||||||
|
desc.textContent = item.description;
|
||||||
|
|
||||||
|
if (filename === "h5-nav") {
|
||||||
|
if (item.credits === "itch") desc.innerHTML += '<br>Credits: Game can be found <a target="_blank" href="https://itch.io">here</a>.';
|
||||||
|
if (item.credits === "nowgg") desc.innerHTML += '<br>Credits: Game can be found <a target="_blank" href="https://now.gg">here</a>.';
|
||||||
|
}
|
||||||
|
|
||||||
|
a.appendChild(img);
|
||||||
|
a.appendChild(title);
|
||||||
|
a.appendChild(desc);
|
||||||
|
|
||||||
|
// Which function is used for the click event is determined by
|
||||||
|
// the corresponding location/index in the dirnames object.
|
||||||
|
const functionsList = [
|
||||||
|
() => goFrame(item.path),
|
||||||
|
() => goFrame("/?eg&core=" + item.core + "&rom=" + item.rom),
|
||||||
|
item.custom ? () => goProx[item.custom]("stealth") : () => goFrame("/archive/g/" + item.path)
|
||||||
|
];
|
||||||
|
|
||||||
|
a.addEventListener("click", clickHandler(functionsList[Object.values(dirnames).indexOf(dir)], a));
|
||||||
|
|
||||||
|
navList.appendChild(a);
|
||||||
}
|
}
|
||||||
};
|
break;
|
||||||
|
|
||||||
for (let item of data) {
|
|
||||||
// Load each item as an anchor tag with an image, heading,
|
|
||||||
// description, and click event listener.
|
|
||||||
let a = document.createElement("a");
|
|
||||||
a.href = "#";
|
|
||||||
|
|
||||||
let img = document.createElement("img");
|
|
||||||
img.src = `/assets/img/${dir}/` + item.img;
|
|
||||||
let title = document.createElement("h3");
|
|
||||||
title.textContent = item.name;
|
|
||||||
let desc = document.createElement("p");
|
|
||||||
desc.textContent = item.description;
|
|
||||||
|
|
||||||
if (filename === "h5-nav") {
|
|
||||||
if (item.credits === "itch") desc.innerHTML += '<br>Credits: Game can be found <a target="_blank" href="https://itch.io">here</a>.';
|
|
||||||
if (item.credits === "nowgg") desc.innerHTML += '<br>Credits: Game can be found <a target="_blank" href="https://now.gg">here</a>.';
|
|
||||||
}
|
|
||||||
|
|
||||||
a.appendChild(img);
|
|
||||||
a.appendChild(title);
|
|
||||||
a.appendChild(desc);
|
|
||||||
|
|
||||||
// Which function is used for the click event is determined by
|
|
||||||
// the corresponding location/index in the dirnames object.
|
|
||||||
const functionsList = [
|
|
||||||
() => goFrame(item.path),
|
|
||||||
() => goFrame("/?eg&core=" + item.core + "&rom=" + item.rom),
|
|
||||||
() => item.custom ? goProx[item.custom]("stealth") : goFrame("/archive/g/" + item.path)
|
|
||||||
];
|
|
||||||
|
|
||||||
a.addEventListener("click", clickHandler(functionsList[Object.values(dirnames).indexOf(dir)], a));
|
|
||||||
|
|
||||||
navList.appendChild(a);
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
case "flash-nav":
|
||||||
|
for (let item of data) {
|
||||||
|
// Load each item as an anchor tag with a short title and click
|
||||||
|
// event listener.
|
||||||
|
let a = document.createElement("a");
|
||||||
|
a.href = "#";
|
||||||
|
a.textContent = item.slice(0, -4);
|
||||||
|
|
||||||
|
a.addEventListener("click", e => {
|
||||||
|
e.preventDefault();
|
||||||
|
goFrame("/?fg&swf=" + item);
|
||||||
|
});
|
||||||
|
|
||||||
|
navList.appendChild(a);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
// No default case.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "flash-nav":
|
|
||||||
for (let item of data) {
|
|
||||||
// Load each item as an anchor tag with a short title and click
|
|
||||||
// event listener.
|
|
||||||
let a = document.createElement("a");
|
|
||||||
a.href = "#";
|
|
||||||
a.textContent = item.slice(0, -4);
|
|
||||||
|
|
||||||
a.addEventListener("click", e => {
|
|
||||||
e.preventDefault();
|
|
||||||
goFrame("/?fg&swf=" + item);
|
|
||||||
});
|
|
||||||
|
|
||||||
navList.appendChild(a);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// No default case.
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})();
|
||||||
})();
|
});
|
Loading…
Add table
Add a link
Reference in a new issue