More tidying of common.js. Emerald I'm still going to eat you alive for this

This commit is contained in:
00Fjongl 2024-07-09 00:53:51 -05:00
parent 02e3f6dbb2
commit 52efec3944

View file

@ -29,7 +29,7 @@ const UrlHandler = parser => typeof parser === "function"
stealth ? goFrame(url, nolag) : location.href = url; stealth ? goFrame(url, nolag) : location.href = url;
} }
: (stealth, nolag) => { : (stealth, nolag) => {
stealth ? goFrame(url, nolag) : location.href = url; stealth ? goFrame(parser, nolag) : location.href = parser;
}; };
// An asynchronous version of the function above, just in case. // An asynchronous version of the function above, just in case.
@ -49,23 +49,21 @@ const setAuthCookie = (s, lax) => {
// Search engine is set to Bing. Intended to work just like the usual // Search engine is set to Bing. Intended to work just like the usual
// bar at the top of a browser. // bar at the top of a browser.
const sx = "bing.com" + "/search?q="; const sx = "bing.com" + "/search?q=";
/*
const omnibox = url => const omnibox = url =>
(url.indexOf("http") (url.indexOf("http")
? "https://" + (url.indexOf(".") < 1 ? sx : "") ? "https://" + (url.indexOf(".") < 1 ? sx : "")
: "") : "")
+ url; + url;
*/
// Parse a URL to use with Ultraviolet. // Another omnibox function. Unsure if the version above is needed.
const uvUrl = url => location.origin + __uv$config.prefix + __uv$config.encodeUrl(omnibox(url));
/* RAMMERHEAD CONFIGURATION */
// Another omnibox function. Unsure if the version further above is needed.
const search = (input, template) => { const search = (input, template) => {
try { try {
// Return the input if it is already a valid URL. // Return the input if it is already a valid URL.
// eg: https://example.com, https://example.com/test?q=param // eg: https://example.com, https://example.com/test?q=param
return new URL(input).toString(); return new URL(input) + "";
} catch (err) { } catch (err) {
// Continue if it is invalid. // Continue if it is invalid.
} }
@ -75,7 +73,7 @@ const search = (input, template) => {
// eg: example.com, https://example.com/test?q=param // eg: example.com, https://example.com/test?q=param
const url = new URL(`http://${input}`); const url = new URL(`http://${input}`);
// Return only if the hostname has a TLD or a subdomain. // Return only if the hostname has a TLD or a subdomain.
if (url.hostname.indexOf(".") != -1) return url.toString(); if (url.hostname.indexOf(".") != -1) return url + "";
} catch (err) { } catch (err) {
// Continue if it is invalid. // Continue if it is invalid.
} }
@ -84,7 +82,12 @@ const search = (input, template) => {
return template.replace("%s", encodeURIComponent(input)); return template.replace("%s", encodeURIComponent(input));
}; };
// Parse a URL to use with Rammerhead. // Parse a URL to use with Ultraviolet.
const uvUrl = url => location.origin + __uv$config.prefix + __uv$config.encodeUrl(search(url, sx + "%s"));
/* RAMMERHEAD CONFIGURATION */
// Parse a URL to use with Rammerhead. Only usable if the server is active.
const RammerheadEncode = async baseUrl => { const RammerheadEncode = async baseUrl => {
// Hellhead // Hellhead
const mod = (n, m) => ((n % m) + m) % m; const mod = (n, m) => ((n % m) + m) % m;
@ -322,7 +325,7 @@ const goProx = {
// setAuthCookie("__cor_auth=1", false); // setAuthCookie("__cor_auth=1", false);
ultraviolet: UrlHandler(uvUrl), ultraviolet: UrlHandler(uvUrl),
rammerhead: asyncUrlHandler(async () => location.origin + (await RammerheadEncode(omnibox(url)))), rammerhead: asyncUrlHandler(async () => location.origin + (await RammerheadEncode(search(url, sx + "%s")))),
searx: UrlHandler(location.protocol + `//c.${getDomain()}/engine/`), searx: UrlHandler(location.protocol + `//c.${getDomain()}/engine/`),