forked from sent/waves
Okay I actually gotta study now
This commit is contained in:
parent
ec39325750
commit
4155527237
|
@ -1,4 +1,40 @@
|
|||
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/`;
|
||||
let currentWispUrl = localStorage.getItem('customWispUrl') || defaultWispUrl;
|
||||
const wispUrl = currentWispUrl;
|
||||
|
@ -7,24 +43,17 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
async function registerSW() {
|
||||
try {
|
||||
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;
|
||||
}
|
||||
|
||||
await ensureWebSocketConnection(wispUrl);
|
||||
|
||||
console.log("%c[⚙️]%c Registering Service Worker...", "color: #007bff; font-weight: bold;", "color: #007bff;");
|
||||
await navigator.serviceWorker.register("/wah/sw.js", {
|
||||
scope: '/wah/a/'
|
||||
});
|
||||
console.log("%c[✅]%c Service Worker registered successfully.", "color: green; font-weight: bold;", "color: green;");
|
||||
|
||||
console.log("%c[+]%c Registering Service Worker...", "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
|
||||
await navigator.serviceWorker.register("/wah/sw.js", { scope: '/wah/a/' });
|
||||
console.log("%c[*]%c Service Worker registered successfully.", "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
|
||||
const savedTransport = localStorage.getItem('transport') || "epoxy";
|
||||
switchTransport(savedTransport);
|
||||
updateTransportUI(savedTransport);
|
||||
|
||||
console.log(`%c[🚀]%c Using ${savedTransport} transport.`, "color: #ffffff 255, 255); font-weight: bold;", "color: #ffffff;");
|
||||
|
||||
console.log(`%c[#]%c Using ${capitalizeTransport(savedTransport)} transport.`, "background-color: black; color: white; font-weight: bold;", "background-color: black; color: white;");
|
||||
} catch (error) {
|
||||
logError(error, 'An error occurred during Service Worker registration or WebSocket connection');
|
||||
}
|
||||
|
@ -32,31 +61,28 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
|
||||
async function ensureWebSocketConnection(url) {
|
||||
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);
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
ws.onerror = (error) => {
|
||||
logError(error, 'Failed to establish WebSocket connection');
|
||||
reject(error);
|
||||
};
|
||||
|
||||
ws.onclose = (event) => {
|
||||
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 {
|
||||
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) {
|
||||
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) {
|
||||
|
@ -64,12 +90,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
"epoxy": "/epoxy/index.mjs",
|
||||
"libcurl": "/libcurl/index.mjs"
|
||||
};
|
||||
|
||||
const transportFile = transportMap[transport];
|
||||
if (transportFile) {
|
||||
connection.setTransport(transportFile, [{
|
||||
wisp: wispUrl
|
||||
}]);
|
||||
connection.setTransport(transportFile, [{ wisp: wispUrl }]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +108,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
|
||||
function updateTransportUI(transport) {
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user