Skip to content

Commit

Permalink
Merge pull request #3 from titaniumnetwork-dev/scramjet
Browse files Browse the repository at this point in the history
Add Scramjet
  • Loading branch information
MotorTruck1221 authored Dec 19, 2024
2 parents 406100a + c3edb0b commit 8c5c554
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/scramjet"]
path = vendor/scramjet
url = https://github.com/mercuryworkshop/scramjet
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@
# 1.1.1
- Fixes a bug where if games aren't enabled it redirects to localhost:8080 over just /
- Fixes a bug where if games aren't enabled, it still loads and compresses images over just ignoring them.

# 1.1.2
- Fixes bugs with apps opening as the full url instead of just the correct link
- Fixes a bug with the iFrame panel where it copies & pastes the full link instead of just the normal link.
- Add Scramjet
6 changes: 6 additions & 0 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { defineConfig, envField } from 'astro/config';
import { viteStaticCopy } from 'vite-plugin-static-copy';
//we need the buildOpts from here : D
import { parsedDoc } from './server/config/config.ts';
const scramjetPath = `${import.meta.dirname}/vendor/scramjet/dist/`

// https://astro.build/config
export default defineConfig({
Expand Down Expand Up @@ -63,6 +64,11 @@ export default defineConfig({
dest: 'baremux',
overwrite: false,
},
{
src: `${scramjetPath}/**/*`.replace(/\\/g, '/'),
dest: 'scram',
overwrite: false
}
],
}),
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "incognito",
"version": "1.1.1",
"version": "1.1.2",
"private": true,
"type": "module",
"dependencies": {
Expand Down
25 changes: 21 additions & 4 deletions public/sw.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
importScripts('/uv/uv.bundle.js');
importScripts('/uv/uv.config.js');
importScripts(
'/uv/uv.bundle.js',
'/uv/uv.config.js',
'/scram/scramjet.wasm.js',
'/scram/scramjet.shared.js',
'/scram/scramjet.worker.js'
);
importScripts(__uv$config.sw || '/uv/uv.sw.js');
const uv = new UVServiceWorker();
const sj = new ScramjetServiceWorker();
(async function () {
await sj.loadConfig();
})();
self.addEventListener('fetch', function (event) {
if (event.request.url.startsWith(location.origin + __uv$config.prefix)) {
event.respondWith(
(async function () {
return await uv.fetch(event);
})(),
);
} else {
}
else if (sj.route(event)) {
event.respondWith(
(async function() {
return await sj.fetch(event);
})()
);
}
else {
event.respondWith(
(async function () {
return await fetch(event.request);
})(),
})()
);
}
});
Expand Down
1 change: 0 additions & 1 deletion public/uv/uv.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
self.__uv$config = {
prefix: '/~/uv/',
bare: '/bare/',
encodeUrl: function encode(str) {
if (!str) return str;
return encodeURIComponent(
Expand Down
23 changes: 13 additions & 10 deletions src/components/FrameManager.astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { Icon } from 'astro-icon/components';
</div>
</div>
<script>
import { navigate } from 'astro:transitions/client';
import { navigate } from 'astro:transitions/client';
function defineVars() {
const iframe = document.getElementById("iframe") as HTMLIFrameElement;
const iframe = document.getElementById("iframe") as DieTS;
const win = iframe.contentWindow;
//return both the iframe and the iframe's window
//Usage: [variable].iframe or [variable].win
Expand All @@ -29,29 +29,32 @@ import { Icon } from 'astro-icon/components';
const vars = defineVars();
if (vars?.win?.__uv) {
navigator.clipboard.writeText(new URL('./?link=' + encodeURIComponent(__uv$config.encodeUrl!(vars?.win?.__uv.location.href)), location.href).href);
}
}
else if (vars?.win?.$scramjet) {
navigator.clipboard.writeText(new URL(`./?link=${encodeURIComponent(
vars?.win?.location.href
.replace(vars?.win?.location.origin, '')
.replace(vars?.win?.$scramjet.config.prefix, '')
)}`, location.href).href);
}
}
window.exitIframe = function() {
const vars = defineVars();
if (vars?.win?.__uv || vars?.win?.__get$ProxyUrl) {
if (vars?.win?.__uv || vars?.win?.__get$ProxyUrl || vars?.win?.$scramjet) {
navigate("/");
}
}
window.refreshIframe = function() {
const vars = defineVars();
if (vars?.win?.__uv || vars?.win?.__get$ProxyUrl) {
if (vars?.win?.__uv || vars?.win?.__get$ProxyUrl || vars?.win?.$scramjet) {
vars?.win?.location.reload();
}
}
window.setTitle = function() {
const vars = defineVars();
if (vars?.win && vars?.win?.__uv || vars?.win?.__get$ProxyUrl) {
if (vars?.win && vars?.win?.__uv || vars?.win?.__get$ProxyUrl || vars?.win?.$scramjet) {
//@ts-ignore this is really complicated and I am not in the mood to deal with it
document.getElementById("title").value = Object.getOwnPropertyDescriptor(Document.prototype, 'title').get.call(vars?.win.document);
}
if (localStorage.getItem("incog||proxy") === "rh") {
const linkElement = document.getElementById("createlink") as HTMLButtonElement;
linkElement.classList.add("hidden");
}
}
</script>
6 changes: 5 additions & 1 deletion src/components/Scripts.astro
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
search.src = '/search.js';
search.defer = true;
document.body.appendChild(search);
const sj = document.createElement('script');
sj.src = "/scram/scramjet.controller.js";
sj.defer = true;
document.body.appendChild(sj);
const checkScripts = setInterval(() => {
//If both of these aren't defined this will repeat until they are
//this allows use to wait for all of the scripts to be ready *before* we setup the serviceworker
if (typeof __uv$config !== 'undefined') {
if (typeof __uv$config !== 'undefined' && typeof ScramjetController !== 'undefined') {
clearInterval(checkScripts);
resolve();
}
Expand Down
38 changes: 22 additions & 16 deletions src/components/Search.astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ import FrameManager from '@components/FrameManager.astro';
import { BareClient } from "@mercuryworkshop/bare-mux";
//simple script I wrote so I don't have to repeat myself (located at: src/ts/serviceWorker.ts)
import { initServiceWorker } from "@scripts/serviceWorker.ts";
let scram: typeof ScramjetController;
//sets the style of the iframe and enables the little panel at the top
async function prox(term: string) {
async function prox(term: string, sj?: typeof ScramjetController) {
let url;
if (localStorage.getItem("incog||proxy") === "uv") {
url = __uv$config!.prefix + __uv$config.encodeUrl!(search(term, localStorage.getItem("incog||search") as string))
} else if (localStorage.getItem("incog||proxy") === "sj") {}
}
else if (localStorage.getItem("incog||proxy") === "sj") {
url = sj.encodeUrl(search(term, localStorage.getItem("incog||search") as string));
}
const iframe = document.getElementById("iframe") as HTMLIFrameElement;
const frameManager = document.getElementById("framemanager") as HTMLElement;
frameManager.classList.remove("hidden");
Expand All @@ -35,38 +39,40 @@ import FrameManager from '@components/FrameManager.astro';
return;
}
}
document.addEventListener("DOMContentLoaded", () => {
initServiceWorker().then(() => { console.log('Service worker active!') });
document.addEventListener("DOMContentLoaded", async () => {
scram = initServiceWorker().then(async (sj): Promise<typeof ScramjetController> => {
console.log('SW active');
return sj;
});
});
//define all of our events and if there is a link proxy it and set the history to /
document.addEventListener("astro:page-load", function () {
document.addEventListener("astro:page-load", async function () {
let links: URLSearchParams = new URLSearchParams(window.location.search);
const link = links.get('link');
const client = new BareClient();
scram = await scram;
//this is in a try {} catch {} as to not pollute the console with errors
//it will error due to this running on every page and not just this one
try {
if (link) {
prox(__uv$config!.prefix + link);
prox(search(localStorage.getItem("incog||proxy") === "uv" ? __uv$config.decodeUrl!(link): scram.decodeUrl(link), localStorage.getItem("incog||search") as string), scram);
history.pushState({}, "", "/");
}
const formInput = document.getElementById("form-input") as HTMLInputElement;
document.getElementById("form-submit")?.addEventListener("click", function () {
initServiceWorker().then(() => {
const iframe = document.getElementById("iframe") as HTMLIFrameElement;
if (!iframe) {
return;
}
prox(formInput?.value)
})
document.getElementById("form-submit")?.addEventListener("click", async function () {
const iframe = document.getElementById("iframe") as HTMLIFrameElement;
if (!iframe) {
return;
}
prox(formInput?.value, scram);
})
document.getElementById("form-input")?.addEventListener("keypress", function (event: any) {
document.getElementById("form-input")?.addEventListener("keypress", async function (event: any) {
if (event.key === "Enter") {
const iframe = document.getElementById("iframe") as HTMLIFrameElement;
if (!iframe) {
return;
}
prox(formInput?.value)
prox(formInput?.value, scram);
}
})
document.getElementById("form-input")?.addEventListener("input", async function() {
Expand Down
2 changes: 2 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ type Suggestion = {
};
declare var BareMux: any;
declare var EpxMod: any;
declare var ScramjetController: any;
declare var $scramjet: any;
1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare global {
setTitle(): void;
__uv: any;
__get$ProxyUrl: any;
$scramjet: any;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/apps.astro
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const images = import.meta.glob<{ default: ImageMetadata }>(
<script>
import { navigate } from "astro:transitions/client";
window.openApp = function(url: string) {
navigate("/?link=" + __uv$config.encodeUrl!(url));
navigate(`/?link=${localStorage.getItem("incog||proxy") === "uv" ? __uv$config.encodeUrl!(url) : $scramjet.codec.encode(url)}`);
}
window.searchApps = function(val: string) {
let elements: NodeListOf<HTMLElement> = document.querySelectorAll('[data-name]');
Expand Down
2 changes: 1 addition & 1 deletion src/pages/options/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import { Icon } from 'astro-icon/components';
</li>
<li
id="sj"
class="py-[20px] px-[18px] cursor-pointer list-none color-[--text-color] hover:underline text-[14px] pointer-events-none opacity-[0.6]"
class="py-[20px] px-[18px] cursor-pointer list-none color-[--text-color] hover:underline text-[14px] border-b-[1px] border-b-[--border-color]"
onclick="setProxy('sj')"
>
Scramjet (coming soon)
Expand Down
44 changes: 23 additions & 21 deletions src/ts/serviceWorker.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
function initServiceWorker() {
return new Promise<void>((resolve) => {
if (localStorage.getItem('incog||proxy') === 'uv') {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(async () => {
//await registerRemoteListener(sw.active!)
console.log('Service Worker Ready');
//@ts-ignore these are a fucking thing
//wait for the scripts to load
await window.loadProxyScripts();
//@ts-ignore these fucking exist
//make sure the transport is set before continuing
await window.setTransport(localStorage.getItem('incog||transport'));
resolve();
function initServiceWorker() {
return new Promise<typeof ScramjetController>((resolve) => {
if ('serviceWorker' in navigator) {
console.log('OOGOGOGOGO');
//@ts-ignore these are a fucking thing
//wait for the scripts to load
const scram = window.loadProxyScripts().then(async (): typeof ScramjetController => {
const scramjet = new ScramjetController({
prefix: "/~/scramjet/",
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"
}
});
navigator.serviceWorker.register('/sw.js', { scope: '/' });
}
} else {
//@ts-ignore
window.loadProxyScripts().then(() => {
resolve();
//@ts-ignore these fucking exist
//make sure the transport is set before continuing
await window.setTransport(localStorage.getItem('incog||transport'));
await scramjet.init('/sw.js');
return scramjet;
});
}
return resolve(scram);
};
});
}

Expand Down
1 change: 1 addition & 0 deletions vendor/scramjet
Submodule scramjet added at 1efcf8

0 comments on commit 8c5c554

Please sign in to comment.