Added binary decoding.

This commit is contained in:
DebaucheryLibrarian 2025-03-03 18:42:37 +00:00
parent 79fc530fb5
commit 5582c0909c
1 changed files with 9 additions and 1 deletions

View File

@ -310,7 +310,15 @@
}
function getName() {
const decoded = base32.decode(codeInput.value);
const input = codeInput.value.trim();
if (/^([01]{8}(\s|$))+/.test(input)) {
// decode binary
nameOutput.value = new TextDecoder().decode(new Int8Array(input.split(/\s+/).map((binaryLetter) => parseInt(binaryLetter, 2))));
return;
}
const decoded = base32.decode(input);
const capitalized = decoded.split(' ').map((word) => `${word.slice(0, 1).toUpperCase()}${word.slice(1)}`).join(' ');
nameOutput.value = capitalized.replace(/#+$/, '');