mirror of
https://github.com/NebulaServices/Nebula.git
synced 2025-05-13 12:00:01 -04:00
A whole bunch of shit
This commit is contained in:
parent
920d9f198f
commit
1616fa21f2
6 changed files with 226 additions and 7 deletions
|
@ -25,6 +25,7 @@
|
||||||
*/
|
*/
|
||||||
import { EventHandler } from "@utils/events";
|
import { EventHandler } from "@utils/events";
|
||||||
import { SW, createProxyScripts, checkProxyScripts, createBareMuxConn, setTransport } from "@utils/serviceWorker";
|
import { SW, createProxyScripts, checkProxyScripts, createBareMuxConn, setTransport } from "@utils/serviceWorker";
|
||||||
|
import { Settings } from "@utils/settings";
|
||||||
import { log } from "@utils/index";
|
import { log } from "@utils/index";
|
||||||
const titleText = `
|
const titleText = `
|
||||||
_ _ _ _ ____ _
|
_ _ _ _ ____ _
|
||||||
|
@ -45,8 +46,8 @@
|
||||||
}
|
}
|
||||||
await checkProxyScripts();
|
await checkProxyScripts();
|
||||||
const conn = await createBareMuxConn("/baremux/worker.js");
|
const conn = await createBareMuxConn("/baremux/worker.js");
|
||||||
await setTransport(conn, "libcurl");
|
|
||||||
window.sw = new SW(conn);
|
window.sw = new SW(conn);
|
||||||
|
for await (const _ of Settings.initDefaults()) {};
|
||||||
const { serviceWorker, bareMuxConn, sj } = await window.sw.getSWInfo();
|
const { serviceWorker, bareMuxConn, sj } = await window.sw.getSWInfo();
|
||||||
log({ type: 'info', bg: true, prefix: true }, `General init completed! \n\nServiceWorker: ${serviceWorker.active?.state} \nBareMuxConn: ${bareMuxConn ? 'Active': 'Not active'} \nScramjetController: ${sj ? 'Active' : 'Not active'}`);
|
log({ type: 'info', bg: true, prefix: true }, `General init completed! \n\nServiceWorker: ${serviceWorker.active?.state} \nBareMuxConn: ${bareMuxConn ? 'Active': 'Not active'} \nScramjetController: ${sj ? 'Active' : 'Not active'}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,8 @@ import { VERSION } from "astro:env/client";
|
||||||
import { search, Elements } from "@utils/index";
|
import { search, Elements } from "@utils/index";
|
||||||
import { BareClient } from "@mercuryworkshop/bare-mux";
|
import { BareClient } from "@mercuryworkshop/bare-mux";
|
||||||
import { defaultStore } from "@utils/storage";
|
import { defaultStore } from "@utils/storage";
|
||||||
|
import { Settings } from "@utils/settings";
|
||||||
|
import { setTransport } from "@utils/serviceWorker";
|
||||||
|
|
||||||
type Suggestion = {
|
type Suggestion = {
|
||||||
phrase: string;
|
phrase: string;
|
||||||
|
@ -89,17 +91,31 @@ import { VERSION } from "astro:env/client";
|
||||||
copyright.classList.add("hidden");
|
copyright.classList.add("hidden");
|
||||||
if (defaultStore.getVal(SettingsVals.proxy.proxy.key) === SettingsVals.proxy.proxy.available.automatic) {
|
if (defaultStore.getVal(SettingsVals.proxy.proxy.key) === SettingsVals.proxy.proxy.available.automatic) {
|
||||||
switch(SupportedSites[input.value]) {
|
switch(SupportedSites[input.value]) {
|
||||||
case "uv":
|
case "uv": {
|
||||||
prox(input.value, "uv");
|
prox(input.value, "uv");
|
||||||
break;
|
break;
|
||||||
case "sj":
|
}
|
||||||
|
case "sj": {
|
||||||
prox(input.value, "sj");
|
prox(input.value, "sj");
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
prox(input.value, "uv");
|
prox(input.value, "uv");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch(defaultStore.getVal("proxy") as "uv" | "sj") {
|
||||||
|
case "uv": {
|
||||||
|
prox(input.value, "uv");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "sj": {
|
||||||
|
prox(input.value, "sj");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
input.addEventListener("input", async () => {
|
input.addEventListener("input", async () => {
|
||||||
|
|
87
src/utils/marketplace.ts
Normal file
87
src/utils/marketplace.ts
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
import { log } from "./index";
|
||||||
|
import { StoreManager } from "./storage";
|
||||||
|
import { SettingsVals } from "./values";
|
||||||
|
|
||||||
|
type PluginType = "page" | "serviceWorker";
|
||||||
|
type MarketplacePluginType = "plugin-page" | "plugin-sw";
|
||||||
|
type PackageType = "theme" | MarketplacePluginType;
|
||||||
|
|
||||||
|
interface Plug {
|
||||||
|
name: string;
|
||||||
|
src: string;
|
||||||
|
type: PluginType;
|
||||||
|
remove?: boolean;
|
||||||
|
}
|
||||||
|
interface SWPagePlugin extends Omit<Plug, "name" | "src"> {
|
||||||
|
host: string;
|
||||||
|
html: string;
|
||||||
|
injectTo: "head" | "body";
|
||||||
|
}
|
||||||
|
|
||||||
|
type SWPluginFunction<T extends unknown> = (args: T) => void | unknown;
|
||||||
|
|
||||||
|
type Events =
|
||||||
|
| "abortpayment"
|
||||||
|
| "activate"
|
||||||
|
| "backgroundfetchabort"
|
||||||
|
| "backgroundfetchclick"
|
||||||
|
| "backgroundfetchfail"
|
||||||
|
| "backgroundfetchsuccess"
|
||||||
|
| "canmakepayment"
|
||||||
|
| "contentdelete"
|
||||||
|
| "cookiechange"
|
||||||
|
| "fetch"
|
||||||
|
| "install"
|
||||||
|
| "message"
|
||||||
|
| "messageerror"
|
||||||
|
| "notificationclick"
|
||||||
|
| "notificationclose"
|
||||||
|
| "paymentrequest"
|
||||||
|
| "periodicsync"
|
||||||
|
| "push"
|
||||||
|
| "pushsubscriptionchange"
|
||||||
|
| "sync";
|
||||||
|
|
||||||
|
interface SWPlugin extends Omit<Plug, "src"> {
|
||||||
|
function: string | SWPluginFunction<any>;
|
||||||
|
events: Events[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Theme {
|
||||||
|
name: string;
|
||||||
|
payload: string;
|
||||||
|
video?: string;
|
||||||
|
bgImage?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Marketplace {
|
||||||
|
//create our own subsidized StoreManager with it's own prefix so the marketplace stuff NEVER touches the other data
|
||||||
|
#storage: StoreManager<"nebula||marketplace">;
|
||||||
|
constructor() {
|
||||||
|
this.#storage = new StoreManager("nebula||marketplace");
|
||||||
|
}
|
||||||
|
async installTheme(theme: Theme) {
|
||||||
|
const themes = this.#storage.getVal(SettingsVals.marketPlace.themes)
|
||||||
|
? JSON.parse(this.#storage.getVal(SettingsVals.marketPlace.themes))
|
||||||
|
: [];
|
||||||
|
if (themes.find((t: any) => t === theme.name)) return log({ type: 'error', bg: false, prefix: false, throw: true }, `${theme.name} is already installed!`)
|
||||||
|
themes.push(theme.name);
|
||||||
|
this.#storage.setVal(SettingsVals.marketPlace.themes, JSON.stringify(themes));
|
||||||
|
}
|
||||||
|
|
||||||
|
async installPlugin(plugin: Plug) {
|
||||||
|
const plugins = this.#storage.getVal(SettingsVals.marketPlace.plugins)
|
||||||
|
? JSON.parse(this.#storage.getVal(SettingsVals.marketPlace.plugins))
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const plug = plugins.find(({ name }: { name: string }) => name === plugin.name);
|
||||||
|
if (plug && plug.remove === false) return log({ type: 'error', bg: false, prefix: false, throw: true }, `${plugin.name} is already installed!`);
|
||||||
|
if (plug && plug.remove) { plug.remove = false; return this.#storage.setVal(SettingsVals.marketPlace.plugins, JSON.stringify(plugins)) };
|
||||||
|
plugins.push({ name: plugin.name, src: plugin.src, type: plugin.type } as unknown as Plug);
|
||||||
|
this.#storage.setVal(SettingsVals.marketPlace.plugins, JSON.stringify(plugins));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.mp = Marketplace
|
||||||
|
|
||||||
|
export { Marketplace }
|
|
@ -1,6 +1,7 @@
|
||||||
import { BareMuxConnection } from "@mercuryworkshop/bare-mux";
|
import { BareMuxConnection } from "@mercuryworkshop/bare-mux";
|
||||||
import { defaultStore } from "./storage";
|
import { defaultStore } from "./storage";
|
||||||
import { SettingsVals, WispServers } from "./values";
|
import { SettingsVals, WispServers } from "./values";
|
||||||
|
import { log } from "./index";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a script element and returns it for usage or more modification.
|
* Creates a script element and returns it for usage or more modification.
|
||||||
|
@ -76,7 +77,8 @@ const createBareMuxConn = (worker: string): Promise<BareMuxConnection> => {
|
||||||
const setTransport = (conn: BareMuxConnection, transport?: "libcurl" | "epoxy"): Promise<void> => {
|
const setTransport = (conn: BareMuxConnection, transport?: "libcurl" | "epoxy"): Promise<void> => {
|
||||||
const server = defaultStore.getVal(SettingsVals.proxy.wispServer);
|
const server = defaultStore.getVal(SettingsVals.proxy.wispServer);
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
console.log(`Set wisp server at: ${server ? WispServers[server]: WispServers.default }`);
|
log({ type: 'info', bg: false, prefix: false }, `Set transport: ${transport ? transport : "libcurl"}`);
|
||||||
|
log({ type: 'info', bg: false, prefix: false }, `Set wisp server at: ${server ? WispServers[server]: WispServers.default }`);
|
||||||
if (transport === "epoxy") return resolve(conn.setTransport("/epoxy/index.mjs", [ { wisp: server ? WispServers[server] : WispServers.default }]));
|
if (transport === "epoxy") return resolve(conn.setTransport("/epoxy/index.mjs", [ { wisp: server ? WispServers[server] : WispServers.default }]));
|
||||||
if (transport === "libcurl") return resolve(conn.setTransport("/libcurl/index.mjs", [ { wisp: server ? WispServers[server] : WispServers.default }]));
|
if (transport === "libcurl") return resolve(conn.setTransport("/libcurl/index.mjs", [ { wisp: server ? WispServers[server] : WispServers.default }]));
|
||||||
});
|
});
|
||||||
|
@ -121,7 +123,7 @@ class SW {
|
||||||
const scram = sj();
|
const scram = sj();
|
||||||
(async () => await scram.init())();
|
(async () => await scram.init())();
|
||||||
navigator.serviceWorker.ready.then(async (reg) => {
|
navigator.serviceWorker.ready.then(async (reg) => {
|
||||||
console.log("Service worker ready and active!");
|
log({ type: 'info', prefix: true, bg: false }, 'ServiceWorker ready and active!');
|
||||||
this.#init = { serviceWorker: reg, sj: scram, bareMuxConn: conn };
|
this.#init = { serviceWorker: reg, sj: scram, bareMuxConn: conn };
|
||||||
this.#ready = true;
|
this.#ready = true;
|
||||||
});
|
});
|
||||||
|
|
109
src/utils/settings.ts
Normal file
109
src/utils/settings.ts
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
import { defaultStore } from "./storage";
|
||||||
|
import { SettingsVals, WispServers } from "./values";
|
||||||
|
import { Marketplace } from "./marketplace";
|
||||||
|
import { setTransport } from "./serviceWorker";
|
||||||
|
|
||||||
|
const tab = {
|
||||||
|
ab: (redirect: string) => {
|
||||||
|
window.location.replace(redirect);
|
||||||
|
const win = window.open();
|
||||||
|
const iframe = win!.document.createElement("iframe") as HTMLIFrameElement;
|
||||||
|
win!.document.body.setAttribute('style', 'margin: 0; height: 100vh; width: 100%;');
|
||||||
|
iframe.setAttribute('style', 'border: none; width: 100%; height: 100%; margin: 0;');
|
||||||
|
iframe.src = window.location.href;
|
||||||
|
win!.document.body.appendChild(iframe);
|
||||||
|
},
|
||||||
|
blob: (redirect: string) => {
|
||||||
|
const content = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style type="text/css">
|
||||||
|
body, html {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<iframe style="border: none; width: 100%; height: 100%;" src="${window.location.href}"></iframe>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
window.location.replace(redirect);
|
||||||
|
const blob = new Blob([content], { type: 'text/html' });
|
||||||
|
window.open(URL.createObjectURL(blob), "_blank");
|
||||||
|
},
|
||||||
|
cloak: (cloak: string) => {
|
||||||
|
const fElem = document.getElementById("favicon")! as HTMLLinkElement;
|
||||||
|
const c = (title: string, href: string) => {
|
||||||
|
document.title = title;
|
||||||
|
fElem.href = href;
|
||||||
|
}
|
||||||
|
switch(cloak) {
|
||||||
|
case "google": {
|
||||||
|
c("Google", "/cloaks/google.png");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "wikipedia": {
|
||||||
|
c("Wikipedia", "/cloaks/wikipedia.ico");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "canvas": {
|
||||||
|
c("Dashboard", "/cloaks/canvas.ico");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "classroom": {
|
||||||
|
c("Home", "/cloaks/classroom.ico");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "powerschool": {
|
||||||
|
c("PowerSchool", "/cloaks/ps.ico");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "reset": {
|
||||||
|
defaultStore.setVal(SettingsVals.tab.cloak, "default");
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const proxy = {
|
||||||
|
change: (proxy: "uv" | "sj" | "automatic") => {
|
||||||
|
defaultStore.setVal(SettingsVals.proxy.proxy.key, proxy);
|
||||||
|
},
|
||||||
|
searchEngine: (s: string) => {
|
||||||
|
defaultStore.setVal(SettingsVals.proxy.searchEngine, s);
|
||||||
|
},
|
||||||
|
wisp: (s: string) => {
|
||||||
|
defaultStore.setVal(SettingsVals.proxy.wispServer, s);
|
||||||
|
},
|
||||||
|
transport: async (t: "libcurl" | "epoxy") => {
|
||||||
|
const { bareMuxConn } = await window.sw.getSWInfo();
|
||||||
|
await setTransport(bareMuxConn, t as "libcurl" | "epoxy");
|
||||||
|
defaultStore.setVal(SettingsVals.proxy.transport.key, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function* initDefaults() {
|
||||||
|
yield proxy.change(defaultStore.getVal(SettingsVals.proxy.proxy.key) ? defaultStore.getVal(SettingsVals.proxy.proxy.key) as "uv" | "sj" | "automatic" : "automatic");
|
||||||
|
yield proxy.wisp(defaultStore.getVal(SettingsVals.proxy.wispServer) ? defaultStore.getVal(SettingsVals.proxy.wispServer) : "default");
|
||||||
|
yield proxy.transport(defaultStore.getVal(SettingsVals.proxy.transport.key) ? defaultStore.getVal(SettingsVals.proxy.transport.key) as "libcurl" | "epoxy" : "libcurl");
|
||||||
|
}
|
||||||
|
|
||||||
|
const Settings = {
|
||||||
|
tab,
|
||||||
|
proxy,
|
||||||
|
initDefaults
|
||||||
|
}
|
||||||
|
|
||||||
|
window.settings = Settings;
|
||||||
|
|
||||||
|
export { Settings };
|
|
@ -57,6 +57,8 @@ interface SettingsVals {
|
||||||
cloak: string
|
cloak: string
|
||||||
},
|
},
|
||||||
marketPlace: {
|
marketPlace: {
|
||||||
|
themes: string;
|
||||||
|
plugins: string;
|
||||||
appearance: {
|
appearance: {
|
||||||
video: string;
|
video: string;
|
||||||
image: string;
|
image: string;
|
||||||
|
@ -76,7 +78,7 @@ const SettingsVals: SettingsVals = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
wispServer: "wispServerUrl",
|
wispServer: "wispServer",
|
||||||
proxy: {
|
proxy: {
|
||||||
key: "proxy",
|
key: "proxy",
|
||||||
available: {
|
available: {
|
||||||
|
@ -98,6 +100,8 @@ const SettingsVals: SettingsVals = {
|
||||||
cloak: "cloak"
|
cloak: "cloak"
|
||||||
},
|
},
|
||||||
marketPlace: {
|
marketPlace: {
|
||||||
|
themes: "themes",
|
||||||
|
plugins: "plugins",
|
||||||
appearance: {
|
appearance: {
|
||||||
video: "video",
|
video: "video",
|
||||||
image: "image",
|
image: "image",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue