panic-report/src/main.js

59 lines
1.6 KiB
JavaScript

function b64decode(data) {
let length = (data.length >> 2) * 3;
if (data.length % 4)
length += (data.length % 4) - 1;
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
const table = []
for (let i = 0; i < alphabet.length; i++)
table[alphabet.charCodeAt(i)] = i;
const result = new Uint8Array(length);
for (let i = 0; i < data.length / 4; i++) {
const value =
(table[data.charCodeAt(4 * i + 0)] << 18) |
(table[data.charCodeAt(4 * i + 1)] << 12) |
(table[data.charCodeAt(4 * i + 2)] << 6) |
(table[data.charCodeAt(4 * i + 3)] << 0);
result[3 * i + 0] = value >> 16;
result[3 * i + 1] = value >> 8;
result[3 * i + 2] = value >> 0;
}
if (data.length % 4 == 2) {
const value =
(table[data.charCodeAt(data.length - 2)] << 6) |
(table[data.charCodeAt(data.length - 1)] << 0);
result[result.length - 1] = value >> 4;
}
if (data.length % 4 == 3) {
const value =
(table[data.charCodeAt(data.length - 3)] << 12) |
(table[data.charCodeAt(data.length - 2)] << 6) |
(table[data.charCodeAt(data.length - 1)] << 0);
result[result.length - 2] = value >> 10;
result[result.length - 1] = value >> 2;
}
return result;
}
window.addEventListener('load', function() {
const base64 = window.location.hash.substring(1)
const zlib = b64decode(base64);
const uncompressed = pako.inflate(zlib);
let decoded = new TextDecoder().decode(uncompressed);
const match = /^\[\d+\.\d+\]/m.exec(decoded);
if (match)
decoded = decoded.substring(match.index);
document.getElementById('logs').textContent = decoded;
});