All the little things - diff

Created Diff never expires
4 removals
41 lines
20 additions
57 lines
class Debug {
#username;
constructor(username="") {
this.#username = username
}
toString() {
return `debug_${this.#username}`
}
}

// Extend user object
// Extend user object
function load_debug(user) {
function load_debug(user) {
let debug;
let debug;
try {
try {
debug = JSON.parse(window.name);
debug = JSON.parse(window.name);
} catch (e) {
} catch (e) {
return;
return;
}
}


if (debug instanceof Object) {
if (debug instanceof Object) {
Object.assign(user, debug);
user.debug = new Debug(user.username);
Object.assign(user.debug, debug);
}
}


if(user.verbose){
if(user.debug.debugUser){
user.toString = () => user.debug.toString();
}
if(user.debug.verbose){
console.log(user);
console.log(user);
console.log(user.debug);
}
}


if(user.showAll){
if(user.debug.showAll){
document.querySelectorAll('*').forEach(e=>e.classList.add('display-block'));
document.querySelectorAll('*').forEach(e=>e.classList.add('display-block'));
}
}


if(user.keepDebug){
if(user.debug.keepDebug){
document.querySelectorAll('a').forEach(e=>e.href=append_debug(e.href));
document.querySelectorAll('a').forEach(e=>e.href=append_debug(e.href));
}else{
}else{
document.querySelectorAll('a').forEach(e=>e.href=remove_debug(e.href));
document.querySelectorAll('a').forEach(e=>e.href=remove_debug(e.href));
}
}


window.onerror = e =>alert(e);
window.onerror = e =>alert(e);
}
}


function append_debug(u){
function append_debug(u){
const url = new URL(u);
const url = new URL(u);
url.searchParams.append('__debug__', 1);
url.searchParams.append('__debug__', 1);
return url.href;
return url.href;
}
}


function remove_debug(u){
function remove_debug(u){
const url = new URL(u);
const url = new URL(u);
url.searchParams.delete('__debug__');
url.searchParams.delete('__debug__');
return url.href;
return url.href;
}
}