Okay I actually gotta study now

This commit is contained in:
sent 2025-05-13 20:51:25 -07:00
parent ec39325750
commit 4155527237

View File

@ -1,4 +1,40 @@
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
const originalLog = console.log;
const originalWarn = console.warn;
const originalError = console.error;
const scriptLogs = [];
function isScriptLog(args) {
return args[0] && (args[0].includes('%c[+]%c') || args[0].includes('%c[*]%c') || args[0].includes('%c[#]%c') || args[0].includes('%c[-]%c') || args[0].includes('%c[!]%c'));
}
console.log = function(...args) {
if (isScriptLog(args)) {
scriptLogs.push(args);
}
originalLog.apply(console, args);
};
console.warn = function(...args) {
if (isScriptLog(args)) {
scriptLogs.push(args);
}
originalWarn.apply(console, args);
};
console.error = function(...args) {
if (isScriptLog(args)) {
scriptLogs.push(args);
}
originalError.apply(console, args);
};
setInterval(() => {
const currentLogs = [...scriptLogs];
console.clear();
currentLogs.forEach(log => originalLog.apply(console, log));
}, 400);
const defaultWispUrl = `${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host}/w/`; const defaultWispUrl = `${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host}/w/`;
let currentWispUrl = localStorage.getItem('customWispUrl') || defaultWispUrl; let currentWispUrl = localStorage.getItem('customWispUrl') || defaultWispUrl;
const wispUrl = currentWispUrl; const wispUrl = currentWispUrl;
@ -7,24 +43,17 @@ document.addEventListener('DOMContentLoaded', function() {
async function registerSW() { async function registerSW() {
try { try {
if (!navigator.serviceWorker) { if (!navigator.serviceWorker) {
console.log("%c[⚠️]%c Service Workers are not supported by this browser.", "color: orange; font-weight: bold;", "color: black;"); console.log("%c[!]%c Service Workers are not supported by this browser.", "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
return; return;
} }
await ensureWebSocketConnection(wispUrl); await ensureWebSocketConnection(wispUrl);
console.log("%c[+]%c Registering Service Worker...", "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
console.log("%c[⚙️]%c Registering Service Worker...", "color: #007bff; font-weight: bold;", "color: #007bff;"); await navigator.serviceWorker.register("/wah/sw.js", { scope: '/wah/a/' });
await navigator.serviceWorker.register("/wah/sw.js", { console.log("%c[*]%c Service Worker registered successfully.", "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
scope: '/wah/a/'
});
console.log("%c[✅]%c Service Worker registered successfully.", "color: green; font-weight: bold;", "color: green;");
const savedTransport = localStorage.getItem('transport') || "epoxy"; const savedTransport = localStorage.getItem('transport') || "epoxy";
switchTransport(savedTransport); switchTransport(savedTransport);
updateTransportUI(savedTransport); updateTransportUI(savedTransport);
console.log(`%c[#]%c Using ${capitalizeTransport(savedTransport)} transport.`, "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
console.log(`%c[🚀]%c Using ${savedTransport} transport.`, "color: #ffffff 255, 255); font-weight: bold;", "color: #ffffff;");
} catch (error) { } catch (error) {
logError(error, 'An error occurred during Service Worker registration or WebSocket connection'); logError(error, 'An error occurred during Service Worker registration or WebSocket connection');
} }
@ -32,31 +61,28 @@ document.addEventListener('DOMContentLoaded', function() {
async function ensureWebSocketConnection(url) { async function ensureWebSocketConnection(url) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log("%c[🌐]%c Establishing WebSocket connection...", "color: #007bff; font-weight: bold;", "color: #007bff;"); console.log("%c[+]%c Establishing WebSocket connection...", "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
const ws = new WebSocket(url); const ws = new WebSocket(url);
ws.onopen = () => { ws.onopen = () => {
console.log("%c[✅]%c WebSocket connection established.", "color: green; font-weight: bold;", "color: green;"); console.log("%c[*]%c WebSocket connection established.", "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
resolve(ws); resolve(ws);
}; };
ws.onerror = (error) => { ws.onerror = (error) => {
logError(error, 'Failed to establish WebSocket connection'); logError(error, 'Failed to establish WebSocket connection');
reject(error); reject(error);
}; };
ws.onclose = (event) => { ws.onclose = (event) => {
if (event.code !== 1000) { if (event.code !== 1000) {
console.warn(`%c[⚠️]%c WebSocket connection closed. Reason: ${event.reason || "No reason provided"}`, "color: orange; font-weight: bold;", "color: orange;"); console.warn(`%c[-]%c WebSocket connection closed. Reason: ${event.reason || "No reason provided"}`, "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
} else { } else {
console.warn("%c[⚠️]%c WebSocket connection closed normally.", "color: orange; font-weight: bold;", "color: orange;"); console.warn("%c[-]%c WebSocket connection closed normally.", "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
} }
}; };
}); });
} }
function logError(error, message) { function logError(error, message) {
console.error(`%c[]%c ${message}: ${error.message || error}`, "color: red; font-weight: bold;", "color: red;"); console.error(`%c[!]%c ${message}: ${error.message || error}`, "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
} }
function switchTransport(transport) { function switchTransport(transport) {
@ -64,12 +90,9 @@ document.addEventListener('DOMContentLoaded', function() {
"epoxy": "/epoxy/index.mjs", "epoxy": "/epoxy/index.mjs",
"libcurl": "/libcurl/index.mjs" "libcurl": "/libcurl/index.mjs"
}; };
const transportFile = transportMap[transport]; const transportFile = transportMap[transport];
if (transportFile) { if (transportFile) {
connection.setTransport(transportFile, [{ connection.setTransport(transportFile, [{ wisp: wispUrl }]);
wisp: wispUrl
}]);
} }
} }
@ -85,7 +108,11 @@ document.addEventListener('DOMContentLoaded', function() {
function updateTransportUI(transport) { function updateTransportUI(transport) {
const transportSelected = document.querySelector(".transport-selected"); const transportSelected = document.querySelector(".transport-selected");
transportSelected.textContent = transport.charAt(0).toUpperCase() + transport.slice(1); transportSelected.textContent = capitalizeTransport(transport);
}
function capitalizeTransport(transport) {
return transport.charAt(0).toUpperCase() + transport.slice(1).toLowerCase();
} }
document.addEventListener('wispUrlChanged', function(e) { document.addEventListener('wispUrlChanged', function(e) {