Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
NebulaServices
GitHub Repository: NebulaServices/Nebula
Path: blob/main/src/utils/settings.ts
976 views
1
import { defaultStore } from "./storage";
2
import { SettingsVals, WispServers } from "./values";
3
import { Marketplace } from "./marketplace";
4
import { setTransport, SW } from "./serviceWorker";
5
6
const tab = {
7
ab: (redirect: string) => {
8
const win = window.open();
9
if (!win) return;
10
window.location.replace(redirect);
11
const iframe = win.document.createElement("iframe") as HTMLIFrameElement;
12
win.document.body.setAttribute('style', 'margin: 0; height: 100vh; width: 100%;');
13
iframe.setAttribute('style', 'border: none; width: 100%; height: 100%; margin: 0;');
14
iframe.src = window.location.href;
15
win.document.body.appendChild(iframe);
16
},
17
blob: (redirect: string) => {
18
const win = window.open();
19
if (!win) return;
20
window.location.replace(redirect);
21
const content = `
22
<!DOCTYPE html>
23
<html>
24
<head>
25
<style type="text/css">
26
body, html {
27
margin: 0;
28
padding: 0;
29
height: 100%;
30
width: 100%;
31
overflow: hidden;
32
}
33
</style>
34
</head>
35
<body>
36
<iframe style="border: none; width: 100%; height: 100%;" src="${window.location.href}"></iframe>
37
</body>
38
</html>
39
`;
40
const blob = new Blob([content], { type: 'text/html' });
41
const url = URL.createObjectURL(blob);
42
win.location.href = url;
43
44
},
45
cloak: (cloak: string) => {
46
const fElem = document.getElementById("favicon")! as HTMLLinkElement;
47
const c = (title: string, href: string) => {
48
document.title = title;
49
fElem.href = href;
50
}
51
switch (cloak) {
52
case "google": {
53
c("Google", "/cloaks/google.png");
54
break;
55
}
56
case "wikipedia": {
57
c("Wikipedia", "/cloaks/wikipedia.ico");
58
break;
59
}
60
case "canvas": {
61
c("Dashboard", "/cloaks/canvas.ico");
62
break;
63
}
64
case "classroom": {
65
c("Home", "/cloaks/classroom.png");
66
break;
67
}
68
case "powerschool": {
69
c("PowerSchool", "/cloaks/ps.ico");
70
break;
71
}
72
case "reset": {
73
defaultStore.setVal(SettingsVals.tab.cloak, "default");
74
window.location.reload();
75
}
76
default: {
77
return;
78
}
79
}
80
}
81
}
82
83
const proxy = {
84
change: (proxy: "uv" | "sj" | "automatic") => {
85
defaultStore.setVal(SettingsVals.proxy.proxy.key, proxy);
86
},
87
searchEngine: (s: string) => {
88
defaultStore.setVal(SettingsVals.proxy.searchEngine, s);
89
},
90
wisp: (s: string) => {
91
defaultStore.setVal(SettingsVals.proxy.wispServer, s);
92
},
93
transport: async (t: "libcurl" | "epoxy") => {
94
const sw = SW.getInstances().next().value!;
95
const { bareMuxConn } = await sw.getSWInfo();
96
await setTransport(bareMuxConn, t as "libcurl" | "epoxy");
97
defaultStore.setVal(SettingsVals.proxy.transport.key, t);
98
}
99
}
100
101
async function* initDefaults() {
102
yield proxy.change(defaultStore.getVal(SettingsVals.proxy.proxy.key) ? defaultStore.getVal(SettingsVals.proxy.proxy.key) as "uv" | "sj" | "automatic" : "automatic");
103
yield proxy.wisp(defaultStore.getVal(SettingsVals.proxy.wispServer) ? defaultStore.getVal(SettingsVals.proxy.wispServer) : "default");
104
yield proxy.transport(defaultStore.getVal(SettingsVals.proxy.transport.key) ? defaultStore.getVal(SettingsVals.proxy.transport.key) as "libcurl" | "epoxy" : "libcurl");
105
yield proxy.searchEngine(defaultStore.getVal(SettingsVals.proxy.searchEngine) ? defaultStore.getVal(SettingsVals.proxy.searchEngine) : "ddg");
106
}
107
108
const Settings = {
109
tab,
110
proxy,
111
initDefaults
112
}
113
114
export { Settings };
115
116