made b64 the default method and fixed the binary method

This commit is contained in:
Boof 2023-08-24 12:59:58 +02:00 committed by GitHub
parent a531bbeb60
commit 4f25adfcd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

@ -1,11 +1,11 @@
function stringToBinary(str) {
return str.split('').map(function (char) {
return char.charCodeAt(0).toString(2);
}).join(' ');
}).join('-');
}
function binaryToString(binary) {
return binary.split(' ').map(function (bin) {
return binary.split('-').map(function (bin) {
return String.fromCharCode(parseInt(bin, 2));
}).join('');
}

View File

@ -6,16 +6,19 @@ const method = document.getElementById("method")
createButton.addEventListener("click", create)
function create() {
out = createMethod()
output.value = "https://thisisaveryshortdomain.asso.eu.org?url=" + out
out, type = createMethod()
output.value = "https://thisisaveryshortdomain.asso.eu.org?type=" + type + "&url=" + out
}
function createMethod() {
var out2
var type2
if (method.value == "binary") {
out2 = stringToBinary(urlInput.value)
type2 = "binary"
} else if (method.value == "b64") {
out2 = btoa(urlInput.value)
type2 = "binary"
}
return out2
return out2, type
}

View File

@ -20,8 +20,8 @@
<label for="method">Select a method</label>
<br>
<select id="method">
<option value="binary">Binary</option>
<option value="b64">Base 64</option>
<option value="binary">Binary</option>
</select>
<br>
<button id="createButton">Create url</button>