Skip to content

Commit

Permalink
feat: added scramjet. it is broken. but it will soon be not
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiteAFancyEmerald committed Dec 19, 2024
1 parent 9fd9183 commit 214716e
Show file tree
Hide file tree
Showing 20 changed files with 577 additions and 96 deletions.
1 change: 1 addition & 0 deletions run-command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ commands: for (let i = 2; i < process.argv.length; i++)
await build({
entryPoints: [
'./views/uv/**/*.js',
'./views/scram/**/*.js',
'./views/assets/js/**/*.js',
'./views/assets/css/**/*.css',
],
Expand Down
1 change: 1 addition & 0 deletions src/routes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ NOT entire folders check src/routes.mjs and add it manually. */
'retro-games': 'pages/nav/emulibrary.html',
/* Proxies */
ultraviolet: 'pages/proxnav/ultraviolet.html',
scramjet: 'pages/proxnav/scramjet.html',
uverror: 'pages/proxnav/ultraviolet-error.html',
rammerhead: 'pages/proxnav/rammerhead.html',
/* Proxy Presets */
Expand Down
17 changes: 17 additions & 0 deletions src/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ app.register(fastifyStatic, {
decorateReply: false,
});

// This combines scripts from the official scramjet repository with local scramjet scripts into
// one directory path. Local versions of files override the official versions.
app.register(fastifyStatic, {
root: [
fileURLToPath(
new URL(
// Use the pre-compiled, minified scripts instead, if enabled in config.
config.minifyScripts ? '../views/dist/scram' : '../views/scram',
import.meta.url
)
),
uvPath,
],
prefix: '/scram/',
decorateReply: false,
});

// Register proxy paths to the website.
app.register(fastifyStatic, {
root: epoxyPath,
Expand Down
18 changes: 17 additions & 1 deletion views/assets/js/common-16451543478.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const setAuthCookie = (s, lax) => {

// Search engine is set to Bing. Intended to work just like the usual
// bar at the top of a browser.
const sx = 'bing.com' + '/search?q=',
const sx = 'startpage.com/sp' + '/search?query=',
/*
omnibox = url =>
(url.indexOf("http")
Expand Down Expand Up @@ -107,6 +107,19 @@ const sx = 'bing.com' + '/search?q=',
url = search(url);
}
return url;
},
// Parse a URL to use with Scramjet.
sjUrl = (url) => {
try {
url =
location.origin +
"/scram/service/" +
search(url);
} catch (e) {
// This is for cases where the SJ scripts have not been loaded.
url = search(url);
}
return url;
};

/* RAMMERHEAD CONFIGURATION */
Expand Down Expand Up @@ -364,6 +377,8 @@ addEventListener('DOMContentLoaded', async () => {
// setAuthCookie("__cor_auth=1", false);
ultraviolet: urlHandler(uvUrl),

scramjet: urlHandler(sjUrl),

rammerhead: asyncUrlHandler(
async (url) => location.origin + (await RammerheadEncode(search(url)))
),
Expand Down Expand Up @@ -451,6 +466,7 @@ addEventListener('DOMContentLoaded', async () => {
};

prSet('pr-uv', 'ultraviolet');
prSet('pr-sj', 'scramjet');
prSet('pr-rh', 'rammerhead');
prSet('pr-yt', 'youtube');
prSet('pr-rh-dc', 'discordRH');
Expand Down
189 changes: 95 additions & 94 deletions views/assets/js/register-sw.js
Original file line number Diff line number Diff line change
@@ -1,98 +1,99 @@
// Encase everything in a new scope so that variables are not accidentally
// attached to the global scope.
(() => {
const stockSW = '/uv/sw.js',
blacklistSW = '/uv/sw-blacklist.js',
swAllowedHostnames = ['localhost', '127.0.0.1'],
connection = new BareMux.BareMuxConnection('/baremux/worker.js'),
wispUrl =
(location.protocol === 'https:' ? 'wss' : 'ws') +
'://' +
location.host +
'/wisp/',
// Proxy configuration
proxyUrl = 'socks5h://localhost:9050', // Replace with your proxy URL
transports = {
epoxy: '/epoxy/index.mjs',
libcurl: '/libcurl/index.mjs',
bare: '/baremux/index.mjs',
},
// The following two variables are copied and pasted here from csel.js.
readCookie = async (name) => {
// Get the first cookie that has the same name.
for (let cookie of document.cookie.split('; '))
if (!cookie.indexOf(name + '='))
// Return the cookie's stored content.
return decodeURIComponent(cookie.slice(name.length + 1));
},
// Sets the default transport mode based on the browser. Firefox is not
// supported by epoxy yet, which is why this is implemented.
defaultMode = /(?:Chrome|AppleWebKit)\//.test(navigator.userAgent)
? 'epoxy'
: 'libcurl';
const stockSW = '/uv/sw.js',
blacklistSW = '/uv/sw-blacklist.js',
swAllowedHostnames = ['localhost', '127.0.0.1'],
connection = new BareMux.BareMuxConnection('/baremux/worker.js'),
wispUrl =
(location.protocol === 'https:' ? 'wss' : 'ws') +
'://' +
location.host +
'/wisp/',
scramjet = new ScramjetController({
prefix: "/scram/service/",
files: {
wasm: "/scram/scramjet.wasm.js",
worker: "/scram/scramjet.worker.js",
client: "/scram/scramjet.client.js",
shared: "/scram/scramjet.shared.js",
sync: "/scram/scramjet.sync.js"
},
flags: {
serviceworkers: true,
syncxhr: true,
scramitize: true,
},
}),
// Proxy configuration
proxyUrl = 'socks5h://localhost:9050', // Replace with your TOR proxy URL (or any)
transports = {
epoxy: '/epoxy/index.mjs',
libcurl: '/libcurl/index.mjs',
bare: '/baremux/index.mjs',
},
// The following two variables are copied and pasted here from csel.js.
readCookie = async (name) => {
// Get the first cookie that has the same name.
for (let cookie of document.cookie.split('; '))
if (!cookie.indexOf(name + '='))
// Return the cookie's stored content.
return decodeURIComponent(cookie.slice(name.length + 1));
},
// Sets the default transport mode based on the browser. Firefox is not
// supported by epoxy yet, which is why this is implemented.
defaultMode = /(?:Chrome|AppleWebKit)\//.test(navigator.userAgent)
? 'epoxy'
: 'libcurl';

transports.default = transports[defaultMode];

// Prevent the transports object from accidentally being edited.
Object.freeze(transports);

const registerSW = async () => {
if (!navigator.serviceWorker) {
if (
location.protocol !== 'https:' &&
!swAllowedHostnames.includes(location.hostname)
)
throw new Error('Service workers cannot be registered without https.');

throw new Error("Your browser doesn't support service workers.");
}

// If the user has changed the transport mode, use that over the default.
const transportMode =
transports[await readCookie('HBTransport')] || transports.default;
let transportOptions = { wisp: wispUrl };

// Only use Tor with the proxy if the user has enabled it in settings.
if ((await readCookie('HBUseOnion')) === 'true')
transportOptions.proxy = proxyUrl;

await connection.setTransport(transportMode, [transportOptions]);

/* Choose a service worker to register based on whether or not the user
* has adblocking enabled. If the user changes this setting, this script needs
* to be reloaded for this to update, such as by refreshing the page.
*/
const registrations = await navigator.serviceWorker.getRegistrations(),
usedSW =
(await readCookie('HBHideAds')) !== 'false' ? blacklistSW : stockSW;

// Unregister a service worker if it isn't the one being used.
for (const registration of registrations)
if (
registration.active &&
new URL(registration.active.scriptURL).pathname !==
new URL(usedSW, location.origin).pathname
)
await registration.unregister();

await navigator.serviceWorker.register(usedSW);
};

transports.default = transports[defaultMode];

// Prevent the transports object from accidentally being edited.
Object.freeze(transports);

const registerSW = async () => {
if (!navigator.serviceWorker) {
if (
location.protocol !== 'https:' &&
!swAllowedHostnames.includes(location.hostname)
)
throw new Error('Service workers cannot be registered without https.');

throw new Error("Your browser doesn't support service workers.");
}

// If the user has changed the transport mode, use that over the default.
const transportMode =
transports[await readCookie('HBTransport')] || transports.default;
let transportOptions = { wisp: wispUrl };

// Only use Tor with the proxy if the user has enabled it in settings.
if ((await readCookie('HBUseOnion')) === 'true')
transportOptions.proxy = proxyUrl;

await connection.setTransport(transportMode, [transportOptions]);

/* Choose a service worker to register based on whether or not the user
* has ads enabled. If the user changes this setting, this script needs
* to be reloaded for this to update, such as by refreshing the page.
*/
const registrations = await navigator.serviceWorker.getRegistrations(),
usedSW =
(await readCookie('HBHideAds')) !== 'false' ? blacklistSW : stockSW;

// Unregister a service worker if it isn't the one being used.
for (const registration of registrations)
if (
registration.active &&
new URL(registration.active.scriptURL).pathname !==
new URL(usedSW, location.origin).pathname
)
await registration.unregister();

await navigator.serviceWorker.register(usedSW);
};

/*
Commented out upon discovering that a duplicate BareMux connection may be
unnecessary; previously thought to have prevented issues with refreshing.
async function setupTransportOnLoad() {
const conn = new BareMux.BareMuxConnection("/baremux/worker.js");
if (await conn.getTransport() !== "/baremux/module.js") {
await conn.setTransport("/libcurl/index.mjs", [{ wisp: wispUrl, proxy: proxyUrl }]);
}
}
// Run transport setup on page load.
setupTransportOnLoad();
*/

registerSW();
})();
// Register the service worker
registerSW();
scramjet.init("/scram/scramjet.sw.js");
})();
Loading

0 comments on commit 214716e

Please sign in to comment.