mirror of
https://codeberg.org/vlw/victorwesterlund.com.git
synced 2025-09-13 19:13:42 +02:00
34 lines
No EOL
645 B
JavaScript
34 lines
No EOL
645 B
JavaScript
// Victor Westerlund - www.victorwesterlund.com
|
|
|
|
class Logging {
|
|
constructor() {
|
|
this.endpoint = "/log/";
|
|
this.data = new URLSearchParams();
|
|
|
|
document.addEventListener("visibilitychange",() => {
|
|
if(document.visibilityState === "hidden") {
|
|
this.send();
|
|
}
|
|
});
|
|
|
|
this.log("foo","bar");
|
|
}
|
|
|
|
log(key,value) {
|
|
this.data.append(key,value);
|
|
}
|
|
|
|
send() {
|
|
const send = navigator.sendBeacon(this.endpoint,this.data);
|
|
if(send !== true) {
|
|
const url = this.endpoint + this.data.toString();
|
|
fetch(url).catch(response => console.log(response));
|
|
}
|
|
}
|
|
}
|
|
|
|
export default class Log {
|
|
constructor(value,key = "u") {
|
|
// WIP
|
|
}
|
|
} |