-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathindex.html
More file actions
428 lines (387 loc) · 22.4 KB
/
index.html
File metadata and controls
428 lines (387 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<head>
<title>Loading...</title>
<link rel="icon" href="https://cdn.jsdelivr.net/gh/mercuryworkshop/scramjet-app@latest/public/favicon.ico">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Sora:wght@100..800&display=swap" rel="stylesheet">
</head>
<body class="default">
<header>
<form id="search"><input id="url" type="text" class="search-input search" placeholder="Search the web or enter URL"></form>
<span id="gear"><i class="fa"></i></span>
</header>
<div id="overlay">
<div id="settings">
<h3 style="margin:auto;">Settings</h3>
<br>
<h4 style="margin:auto;">WISP Server</h4>
<br>
<form style="margin:auto;"id="wispInput">
<input id="websocket" type="text" placeholder="wss://gointospace.app/wisp/" value="wss://gointospace.app/wisp/">
<button type="submit">Set WISP</button>
</form>
<br>
<h4 style="margin:auto;">Transport Protocol</h4>
<br>
<div style="text-align:center;">
<ul style="display:inline-block; text-align:left; list-style-type:none; padding:0; margin:0;">
<li><input type="radio" name="transport" value="epoxy" checked> Epoxy (Default)</li>
<li><input type="radio" name="transport" value="libcurl"> Libcurl</li>
</ul>
</div>
<br>
<h4 style="margin:auto;">Search Engine</h4>
<br>
<select id="searchEnginePicker">
<option value="google">Google</option>
<option value="bing">Bing</option>
<option value="duckduckgo">DuckDuckGo</option>
<option value="brave">Brave (default)</option>
<option value="custom">Custom</option>
</select>
<input id="customSearch" type="text" placeholder="https://search.example.com/search?q=%s" style="display:none; width:100%; margin-top:8px;" />
<br>
<h4 style="margin:auto;">Tab Cloaking</h4>
<br>
<label for="tabCloak">Title</label>
<input id="tabCloak" type="text" placeholder="Khan Academy" style="width:100%; margin-bottom:8px;" />
<label for="tabCloakIcon">Icon (URL)</label>
<input id="tabCloakIcon" type="text" placeholder="https://khanacademy.org/favicon.ico" style="width:100%; margin-bottom:8px;" />
<div class="flex-row" style="margin:auto; margin-bottom:12px;">
<button id="saveTabCloakBtn" type="button">Save Settings</button>
<button id="clearTabCloakBtn" type="button">Clear Settings</button>
<button id="previewTabCloakBtn" type="button">Preview</button>
</div>
<br>
<h4 style="margin:auto;">Theme</h4>
<br>
<select id="themePicker">
<option value="default">Default</option>
<option value="latte">Catppuccin Latte</option>
<option value="frappe">Catppuccin Frappe</option>
<option value="macchiato">Catppuccin Macchiato</option>
<option value="mocha">Catppuccin Mocha</option>
<option value="mrworkshop">Mr. Workshop</option>
<option value="aerialite">Aerialite Labs</option>
</select>
<div id="customThemeSection" style="margin-top:12px;">
<br>
<h4 class="flex-row" style="margin:auto;">Custom Themes</h4> <!--not even supposed to be a flex row i'm just lazy-->
<br>
<input id="customThemeName" type="text" placeholder="Theme name" style="width:100%; margin-bottom:6px;" />
<label style="display:block; font-size:12px; margin-bottom:4px;">Base color</label>
<input id="customThemeBase" type="color" value="#ffffff" style="width:100%; height:30px; margin-bottom:6px;" />
<label style="display:block; font-size:12px; margin-bottom:4px;">Surface color</label>
<input id="customThemeSurface" type="color" value="#f6f6f6" style="width:100%; height:30px; margin-bottom:6px;" />
<label style="display:block; font-size:12px; margin-bottom:4px;">Text color</label>
<input id="customThemeText" type="color" value="#111111" style="width:100%; height:30px; margin-bottom:8px;" />
<div class="flex-row" style="margin:auto; margin-bottom:12px;">
<button id="saveCustomThemeBtn" type="button">Save Theme</button>
<button id="applyCustomThemePreviewBtn" type="button">Preview</button>
</div>
<label style="display:block; font-size:12px; margin-bottom:4px;">Saved themes</label>
<select id="customThemesList" style="width:100%; margin-bottom:8px;"></select>
<div class="flex-row" style="margin:auto; margin-bottom:12px;">
<button id="applyCustomThemeBtn" type="button">Apply</button>
<button id="deleteCustomThemeBtn" type="button">Delete</button>
</div>
</div>
<br>
<h3 style="margin:auto;">TinyJet</h3>
<p style="text-align:center;" id="version">Unable to retrieve version.</p>
<h6 style="margin:auto; font-weight:normal; text-align:center;">A teeny-tiny simple Scramjet implementation and frontend that can be statically hosted.</h6>
<br>
<h4 style="margin:auto;">Credits</h4>
<div style="text-align:center;">
<ul style="display:inline-block; text-align:left; list-style-type:none; padding:0;">
<li><a href="https://github.com/Sophie">Sophie:</a> Maintainer</li>
<li><a href="https://github.com/xmb9">xmb9:</a> Co-maintainer</li>
<li><a href="https://github.com/MercuryWorkshop">Mercury Workshop:</a> <a href="https://github.com/MercuryWorkshop/scramjet">Scramjet</a>, <a href="https://github.com/MercuryWorkshop/wisp-protocol">WISP</a></li>
</ul>
</div>
<p style="margin:auto; text-align:center;">Developed by <a href="https://aerialite.dev">Aerialite Labs</a></p>
</div>
</div>
<iframe id="iframe" width="100%"></iframe>
<script src="https://cdn.jsdelivr.net/gh/AerialiteLabs/tinyjet-frontend@latest/tinyjet/scramjet.all.js" defer></script>
<script type="module" defer>
import * as BareMux from "https://cdn.jsdelivr.net/gh/AerialiteLabs/tinyjet-frontend@latest/tinyjet/index.mjs";
let version = "";
(async function fetchVersion() {
try {
const resp = await fetch('https://api.github.com/repos/AerialiteLabs/tinyjet-frontend/commits?per_page=1');
if (!resp.ok) console.error(`github api returned ${resp.status}`);
const data = await resp.json();
const sha = Array.isArray(data) && data[0] && data[0].sha ? data[0].sha : (data.sha || '');
if (sha) {
version = sha.slice(0, 7);
document.getElementById('version').textContent = version;
}
} catch (e) {
console.debug('could not fetch version from github:', e.message);
version = "Unable to retrieve version info.";
}
})();
const { ScramjetController } = $scramjetLoadController();
const scramjet = new ScramjetController({
files: {
wasm: "https://cdn.jsdelivr.net/gh/AerialiteLabs/tinyjet-frontend@latest/tinyjet/wasm.wasm",
all: "https://cdn.jsdelivr.net/gh/AerialiteLabs/tinyjet-frontend@latest/tinyjet/scramjet.all.js",
sync: "https://cdn.jsdelivr.net/gh/AerialiteLabs/tinyjet-frontend@latest/tinyjet/scramjet.sync.js"
}
});
try {
scramjet.init();
navigator.serviceWorker.register("./sw.js");
} catch (e) { console.error("scramjet failed to initialize;", e); }
const bareworker = `data:application/javascript;base64,IWZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGU9TWVzc2FnZVBvcnQucHJvdG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MpfWNhdGNoKGUpe2EobCxlLCJ3ZWJzb2NrZXQiKX19fW5ldyBCcm9hZGNhc3RDaGFubmVsKCJiYXJlLW11eCIpLnBvc3RNZXNzYWdlKHt0eXBlOiJyZWZyZXNoUG9ydCJ9KSxzZWxmLm9uY29ubmVjdD1lPT57bChlLnBvcnRzWzBdKX0sY29uc29sZS5kZWJ1ZygiYmFyZS1tdXg6IHJ1bm5pbmcgdjIuMS43IChidWlsZCBjNTZkMjg2KSIpfSgpOwovLyMgc291cmNlTWFwcGluZ1VSTD13b3JrZXIuanMubWFw`;
const connection = new BareMux.BareMuxConnection(bareworker);
const settings = document.getElementById("settings");
const gear = document.getElementById("gear");
const overlay = document.getElementById("overlay");
const wispInput = document.getElementById("wispInput");
const transports = document.querySelectorAll('input[name="transport"]');
const themePicker = document.getElementById('themePicker');
const searchEnginePicker = document.getElementById('searchEnginePicker');
const customSearchInput = document.getElementById('customSearch');
const customThemeName = document.getElementById('customThemeName');
const customThemeBase = document.getElementById('customThemeBase');
const customThemeSurface = document.getElementById('customThemeSurface');
const customThemeText = document.getElementById('customThemeText');
const saveCustomThemeBtn = document.getElementById('saveCustomThemeBtn');
const applyCustomThemePreviewBtn = document.getElementById('applyCustomThemePreviewBtn');
const customThemesList = document.getElementById('customThemesList');
const applyCustomThemeBtn = document.getElementById('applyCustomThemeBtn');
const deleteCustomThemeBtn = document.getElementById('deleteCustomThemeBtn');
const tabCloakInput = document.getElementById('tabCloak');
const tabCloakIconInput = document.getElementById('tabCloakIcon');
const saveTabCloakBtn = document.getElementById('saveTabCloakBtn');
const previewTabCloakBtn = document.getElementById('previewTabCloakBtn');
const clearTabCloakBtn = document.getElementById('clearTabCloakBtn');
const originalTitle = "TinyJet Proxy";
function getFaviconElement() {
return document.querySelector('link[rel~="icon"]');
}
const originalFavicon = getFaviconElement() ? getFaviconElement().getAttribute('href') : null;
gear.onclick = () => { overlay.classList.toggle("active"); settings.classList.toggle("open") }
overlay.onclick = e => { if (e.target === overlay) overlay.classList.remove("active"); settings.classList.remove("open") }
document.onkeydown = e => { if (e.key === "Escape") { overlay.classList.remove("active"); settings.classList.remove("open") } }
function getWispUrl() {
const wisp = document.getElementById("websocket").value.trim();
const defaultWisp = "wss://gointospace.app/wisp/";
return wisp || defaultWisp;
}
async function setTransport(transportsel) {
const wispUrl = getWispUrl();
localStorage.setItem('selectedTransport', transportsel);
switch (transportsel) {
case "epoxy":
await connection.setTransport("https://cdn.jsdelivr.net/npm/@mercuryworkshop/epoxy-transport/dist/index.mjs", [{ wisp: wispUrl }]);
break;
case "libcurl":
await connection.setTransport("https://cdn.jsdelivr.net/npm/@mercuryworkshop/libcurl-transport/dist/index.mjs", [{ websocket: wispUrl }]);
break;
default:
await connection.setTransport("https://cdn.jsdelivr.net/npm/@mercuryworkshop/epoxy-transport/dist/index.mjs", [{ wisp: wispUrl }]);
break;
}
}
const searchTemplates = {
google: "https://www.google.com/search?q=%s",
bing: "https://www.bing.com/search?q=%s",
duckduckgo: "https://duckduckgo.com/?q=%s",
brave: "https://search.brave.com/search?q=%s"
};
function search(input) {
try {
return new URL(input).toString();
} catch (err) {}
try {
let url = new URL(`http://${input}`);
if (url.hostname.includes(".")) return url.toString();
} catch (err) {}
const engine = (localStorage.getItem('selectedSearchEngine') || 'brave');
let template;
if (engine === 'custom') {
template = (customSearchInput.value && customSearchInput.value.trim()) || localStorage.getItem('customSearchTemplate') || "";
} else {
template = searchTemplates[engine] || searchTemplates.brave;
}
if (!template) template = searchTemplates.brave;
return template.replace("%s", encodeURIComponent(input));
}
const currentWisp = localStorage.getItem('selectedWisp') || "wss://gointospace.app/wisp/";
const currentTransport = localStorage.getItem('selectedTransport') || "epoxy";
const currentTheme = localStorage.getItem('selectedTheme') || "default";
const currentSearchEngine = localStorage.getItem('selectedSearchEngine') || "brave";
const currentCustomTemplate = localStorage.getItem('customSearchTemplate') || "";
const savedCustomThemes = JSON.parse(localStorage.getItem('customThemes') || '{}');
document.getElementById("websocket").value = currentWisp;
document.querySelector(`input[value="${currentTransport}"]`).checked = true;
themePicker.value = currentTheme;
document.body.className = currentTheme;
searchEnginePicker.value = currentSearchEngine;
customSearchInput.value = currentCustomTemplate;
customSearchInput.style.display = (currentSearchEngine === 'custom') ? 'block' : 'none';
function applyThemeVariables(base, surface, text) {
const root = document.documentElement.style;
root.setProperty('--base', base);
root.setProperty('--surface', surface);
root.setProperty('--text-color', text);
}
function populateCustomThemes() {
customThemesList.innerHTML = '';
const themes = JSON.parse(localStorage.getItem('customThemes') || '{}');
Object.keys(themes).forEach(name => {
const opt = document.createElement('option');
opt.value = name;
opt.textContent = name;
customThemesList.appendChild(opt);
});
}
function applyFavicon(url) {
if (!url) return;
let link = getFaviconElement();
if (!link) {
link = document.createElement('link');
link.rel = 'icon';
document.head.appendChild(link);
}
link.href = url;
}
function applyTabCloak(title, iconUrl) {
if (title) document.title = title;
if (iconUrl) applyFavicon(iconUrl);
}
function restoreOriginalTab() {
document.title = originalTitle;
if (originalFavicon) applyFavicon(originalFavicon);
}
function initTabCloak() {
const savedTitle = localStorage.getItem('cloakedTitle');
const savedIcon = localStorage.getItem('cloakedIcon');
if (savedTitle || savedIcon) {
applyTabCloak(savedTitle, savedIcon);
tabCloakInput.value = savedTitle || '';
tabCloakIconInput.value = savedIcon || '';
} else {
document.title = originalTitle;
}
}
saveTabCloakBtn.addEventListener('click', () => {
const title = tabCloakInput.value.trim();
const icon = tabCloakIconInput.value.trim();
if (!title && !icon) return alert('Enter a title or icon URL to save.');
if (title) localStorage.setItem('cloakedTitle', title); else localStorage.removeItem('cloakedTitle');
if (icon) localStorage.setItem('cloakedIcon', icon); else localStorage.removeItem('cloakedIcon');
applyTabCloak(title, icon);
});
previewTabCloakBtn.addEventListener('click', () => {
const title = tabCloakInput.value.trim();
const icon = tabCloakIconInput.value.trim();
applyTabCloak(title || originalTitle, icon || originalFavicon);
});
clearTabCloakBtn.addEventListener('click', () => {
localStorage.removeItem('cloakedTitle');
localStorage.removeItem('cloakedIcon');
tabCloakInput.value = '';
tabCloakIconInput.value = '';
restoreOriginalTab();
});
saveCustomThemeBtn.addEventListener('click', () => {
const name = customThemeName.value.trim();
if (!name) return alert('Please enter a theme name.');
const themes = JSON.parse(localStorage.getItem('customThemes') || '{}');
themes[name] = {
base: customThemeBase.value,
surface: customThemeSurface.value,
text: customThemeText.value
};
localStorage.setItem('customThemes', JSON.stringify(themes));
populateCustomThemes();
customThemeName.value = '';
});
applyCustomThemePreviewBtn.addEventListener('click', () => {
applyThemeVariables(customThemeBase.value, customThemeSurface.value, customThemeText.value);
});
applyCustomThemeBtn.addEventListener('click', () => {
const sel = customThemesList.value;
if (!sel) return alert('Select a saved theme.');
const themes = JSON.parse(localStorage.getItem('customThemes') || '{}');
const t = themes[sel];
if (!t) return alert('Theme not found.');
applyThemeVariables(t.base, t.surface, t.text);
localStorage.setItem('selectedTheme', `custom:${sel}`);
document.body.className = `custom:${sel}`;
});
deleteCustomThemeBtn.addEventListener('click', () => {
const sel = customThemesList.value;
if (!sel) return alert('Select a saved theme to delete.');
const themes = JSON.parse(localStorage.getItem('customThemes') || '{}');
if (!themes[sel]) return alert('Theme not found');
delete themes[sel];
localStorage.setItem('customThemes', JSON.stringify(themes));
populateCustomThemes();
});
function initSelectedTheme() {
const sel = localStorage.getItem('selectedTheme') || currentTheme;
if (sel && sel.startsWith('custom:')) {
const name = sel.split(':')[1];
const themes = JSON.parse(localStorage.getItem('customThemes') || '{}');
if (themes[name]) {
applyThemeVariables(themes[name].base, themes[name].surface, themes[name].text);
document.body.className = sel;
}
} else {
document.body.className = sel || 'default';
}
}
populateCustomThemes();
initSelectedTheme();
initTabCloak();
setTransport(currentTransport);
wispInput.addEventListener("submit", async (event) => {
event.preventDefault();
const newWisp = document.getElementById("websocket").value.trim();
localStorage.setItem('selectedWisp', newWisp);
const currentTransport = document.querySelector('input[name="transport"]:checked').value;
await setTransport(currentTransport);
});
transports.forEach(radio => {
radio.addEventListener('change', async (event) => {
await setTransport(event.target.value);
});
});
searchEnginePicker.addEventListener('change', (event) => {
const engine = event.target.value;
localStorage.setItem('selectedSearchEngine', engine);
if (engine === 'custom') {
customSearchInput.style.display = 'block';
} else {
customSearchInput.style.display = 'none';
}
});
customSearchInput.addEventListener('blur', (e) => {
const val = e.target.value.trim();
localStorage.setItem('customSearchTemplate', val);
});
customSearchInput.addEventListener('change', (e) => {
const val = e.target.value.trim();
localStorage.setItem('customSearchTemplate', val);
});
themePicker.addEventListener('change', (event) => {
const selectedTheme = event.target.value;
document.body.className = selectedTheme;
localStorage.setItem('selectedTheme', selectedTheme);
});
document.getElementById("search").addEventListener("submit", async (event) => {
event.preventDefault();
let fixedurl = search(document.getElementById("url").value);
let src;
src = scramjet.encodeUrl(fixedurl);
document.getElementById("iframe").src = src;
});
</script>
</body>