2023-07-24 13:29:52 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<title></title>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
<script>
|
2023-07-24 16:53:22 +00:00
|
|
|
function infohashToBase64(infohash) {
|
|
|
|
// Converts an hex infohash into base64.
|
|
|
|
|
|
|
|
// Convert hex into an byte array
|
|
|
|
let byteArray = infohash.replace(/[^0-9a-fA-F]/g, '')
|
2023-07-24 13:29:52 +00:00
|
|
|
.match(/[0-9a-fA-F]{2}/g);
|
2023-07-24 16:53:22 +00:00
|
|
|
for(var i = 0; i<byteArray.length; i++) {
|
|
|
|
byteArray[i] = parseInt(byteArray[i], 16);
|
2023-07-24 13:29:52 +00:00
|
|
|
}
|
|
|
|
|
2023-07-24 16:53:22 +00:00
|
|
|
// Convert byteArray into base64
|
2023-07-24 13:29:52 +00:00
|
|
|
return btoa(
|
|
|
|
String.fromCharCode.apply(
|
|
|
|
null, new Uint8Array(byteArray)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2023-07-24 16:53:22 +00:00
|
|
|
function base64ToInfohash(b64) {
|
|
|
|
// Converts a base64 value into a infohash (in a hex form)
|
|
|
|
|
|
|
|
// Convert base64 into an byteArray
|
|
|
|
let binaryString = atob(b64);
|
|
|
|
let byteArray = new Uint8Array(binaryString.length);
|
2023-07-24 13:29:52 +00:00
|
|
|
for (var i = 0; i < binaryString.length; i++) {
|
2023-07-24 16:53:22 +00:00
|
|
|
byteArray[i] = binaryString.charCodeAt(i);
|
2023-07-24 13:29:52 +00:00
|
|
|
}
|
2023-07-24 16:53:22 +00:00
|
|
|
// Convert byteArray into hex values
|
2023-07-24 13:29:52 +00:00
|
|
|
return Array.from(byteArray, function(byte) {
|
|
|
|
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
|
|
|
|
}).join('');
|
|
|
|
}
|
2023-07-24 14:46:57 +00:00
|
|
|
|
|
|
|
// Everything for the UI itself
|
|
|
|
|
|
|
|
// Holds the state of tabs.
|
2023-07-24 17:55:08 +00:00
|
|
|
// Intended values are "encode", "decode" and "about"
|
2023-07-24 14:46:57 +00:00
|
|
|
let tabOpen = "encode"
|
|
|
|
|
|
|
|
function switchTab(name) {
|
|
|
|
// Switches the tab
|
2023-07-24 14:58:36 +00:00
|
|
|
// only "encode","decode" and "about" values are supported
|
2023-07-24 16:24:05 +00:00
|
|
|
let url = new URL(window.location)
|
|
|
|
url.searchParams.set("tab", name)
|
|
|
|
window.history.replaceState(null, "", url.href)
|
2023-07-24 14:46:57 +00:00
|
|
|
if (name === "encode") {
|
|
|
|
document.getElementById("encode").style.display = "block"
|
|
|
|
document.getElementById("decode").style.display = "none"
|
2023-07-24 14:58:36 +00:00
|
|
|
document.getElementById("about").style.display = "none"
|
2023-07-24 14:46:57 +00:00
|
|
|
} else if (name === "decode") {
|
|
|
|
document.getElementById("encode").style.display = "none"
|
|
|
|
document.getElementById("decode").style.display = "block"
|
2023-07-24 14:58:36 +00:00
|
|
|
document.getElementById("about").style.display = "none"
|
|
|
|
} else if (name === "about") {
|
|
|
|
document.getElementById("encode").style.display = "none"
|
|
|
|
document.getElementById("decode").style.display = "none"
|
|
|
|
document.getElementById("about").style.display = "block"
|
2023-07-24 14:46:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addEventListener("DOMContentLoaded", (event) => {
|
|
|
|
// Get the current query params
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
if (
|
|
|
|
urlParams.has("tab") &&
|
2023-07-24 14:58:36 +00:00
|
|
|
["encode", "decode", "about"].includes(urlParams.get("tab"))
|
2023-07-24 14:46:57 +00:00
|
|
|
) {
|
|
|
|
// Check if tab parameter is set up and is correct
|
|
|
|
// If not, an default value will be used
|
|
|
|
tabOpen = urlParams.get("tab")
|
|
|
|
}
|
|
|
|
switchTab(tabOpen)
|
|
|
|
|
2023-07-24 14:58:36 +00:00
|
|
|
document.getElementsByClassName("tabBar")[0].style.display = "flex"
|
2023-07-24 14:46:57 +00:00
|
|
|
// Show the result of the action performed before reloading
|
|
|
|
if (urlParams.get("tab") === "encode" && urlParams.has("infohashv1")) {
|
|
|
|
document.getElementById("encodeResult").innerText = infohashToBase64(urlParams.get("infohashv1"))
|
|
|
|
} else if (urlParams.get("tab") === "decode" && urlParams.has("base64value")) {
|
|
|
|
document.getElementById("decodeResult").innerText = base64ToInfohash(urlParams.get("base64value"))
|
|
|
|
}
|
|
|
|
});
|
2023-07-24 13:29:52 +00:00
|
|
|
</script>
|
2023-07-24 14:46:57 +00:00
|
|
|
<style>
|
|
|
|
body {
|
2023-07-24 15:37:34 +00:00
|
|
|
width: 100vw; height: 100vh;
|
|
|
|
margin: 0; padding: 0;
|
2023-07-24 14:46:57 +00:00
|
|
|
display: flex; flex-direction: column;
|
2023-07-24 16:24:05 +00:00
|
|
|
justify-content: center;
|
2023-07-24 15:37:34 +00:00
|
|
|
align-items: center;
|
2023-07-24 14:46:57 +00:00
|
|
|
background-color: #10101a;
|
|
|
|
color: white;
|
|
|
|
font-family: monospace;
|
|
|
|
}
|
|
|
|
main {
|
2023-07-24 15:21:28 +00:00
|
|
|
background-color: #202025;
|
2023-07-24 14:46:57 +00:00
|
|
|
padding: 1em;
|
|
|
|
border: 1px solid white;
|
2023-07-24 15:37:34 +00:00
|
|
|
border-radius: 1em;
|
|
|
|
box-shadow: 0px 5px 15px black, 0px 1px 15px black inset;
|
|
|
|
|
2023-07-24 14:46:57 +00:00
|
|
|
}
|
|
|
|
input {
|
|
|
|
color: white;
|
|
|
|
background-color: transparent;
|
2023-07-24 16:24:05 +00:00
|
|
|
border: 1px solid white;
|
2023-07-24 14:46:57 +00:00
|
|
|
}
|
|
|
|
label {
|
|
|
|
margin-right: 0.5rem;
|
|
|
|
}
|
|
|
|
.tab {
|
|
|
|
border: 1px solid white;
|
2023-07-24 15:37:34 +00:00
|
|
|
padding: 1em;
|
2023-07-24 17:55:08 +00:00
|
|
|
border-radius: 0em 0em 1em 1em;
|
2023-07-24 15:37:34 +00:00
|
|
|
box-shadow: 0px 5px 15px black, 0px 1px 15px black inset;
|
2023-07-24 14:46:57 +00:00
|
|
|
}
|
|
|
|
.result:empty { display: none;}
|
|
|
|
.result {
|
|
|
|
background-color: rgba(32, 32, 42, 0.5);
|
|
|
|
margin-top: 1em;
|
|
|
|
padding: 0.5rem;
|
|
|
|
border: 1px solid gray;
|
|
|
|
border-radius: 1em;
|
|
|
|
}
|
2023-07-24 16:24:05 +00:00
|
|
|
.tab, .tabBar {
|
2023-07-24 14:58:36 +00:00
|
|
|
display: none; /* Default value to keep tabs hidden when JS is not available */
|
2023-07-24 14:46:57 +00:00
|
|
|
}
|
|
|
|
.button {
|
2023-07-24 17:55:08 +00:00
|
|
|
flex: 1;
|
|
|
|
text-align: center;
|
2023-07-24 14:46:57 +00:00
|
|
|
padding: 0.5em;
|
|
|
|
border: 1px solid white;
|
|
|
|
border-bottom: none;
|
|
|
|
transition: box-shadow 200ms ease;
|
|
|
|
}
|
2023-07-24 16:24:05 +00:00
|
|
|
.leftButton {
|
|
|
|
border-radius: 1em 0em 0em 0em;
|
|
|
|
}
|
2023-07-24 17:55:08 +00:00
|
|
|
.rightButton {
|
|
|
|
border-radius: 0em 1em 0em 0em;
|
|
|
|
}
|
2023-07-24 14:46:57 +00:00
|
|
|
.button:hover {
|
2023-07-24 15:21:28 +00:00
|
|
|
box-shadow: 0px 5px 25px black;
|
2023-07-24 14:46:57 +00:00
|
|
|
}
|
|
|
|
.button:active {
|
|
|
|
background-color: rgba(255,255,255, 0.2);
|
|
|
|
}
|
2023-07-24 14:58:36 +00:00
|
|
|
a { color: cyan; text-decoration: none;}
|
2023-07-25 12:48:24 +00:00
|
|
|
#about, .noscript {
|
|
|
|
display: block;
|
2023-07-24 15:37:34 +00:00
|
|
|
max-width: 40rem;
|
|
|
|
}
|
2023-07-24 14:46:57 +00:00
|
|
|
</style>
|
2023-07-24 13:29:52 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2023-07-24 14:46:57 +00:00
|
|
|
<main>
|
|
|
|
<h1>infohash ↔ base64</h1>
|
|
|
|
<noscript>
|
2023-07-25 12:48:24 +00:00
|
|
|
<div class="noscript">
|
|
|
|
<p>This tool requires JavaScript to function.</p>
|
|
|
|
<p>You can use DevTools in your browser to look at the code (it's intended to be easily readable).</p>
|
|
|
|
</div>
|
2023-07-24 14:46:57 +00:00
|
|
|
</noscript>
|
|
|
|
<div class="tabBar">
|
2023-07-24 16:24:05 +00:00
|
|
|
<div onclick="switchTab('encode')" class="button leftButton">Encode</div>
|
2023-07-24 14:46:57 +00:00
|
|
|
<div onclick="switchTab('decode')" class="button">Decode</div>
|
2023-07-24 17:55:08 +00:00
|
|
|
<div onclick="switchTab('about')" class="button rightButton">About</div>
|
2023-07-24 14:46:57 +00:00
|
|
|
</div>
|
|
|
|
<div class="tab" id="encode">
|
|
|
|
<form>
|
|
|
|
<h2>Encode</h2>
|
|
|
|
<input type="hidden" name="tab" value="encode" />
|
|
|
|
<label for="infohashv1">infohash v1</label><input type="text" id="infohashv1" name="infohashv1" pattern="[0-9a-f]*" />
|
|
|
|
<input type="submit" method="get" value="convert"/>
|
|
|
|
</form>
|
|
|
|
<div class="result" id="encodeResult"></div>
|
|
|
|
</div>
|
|
|
|
<div class="tab" id="decode">
|
|
|
|
<form>
|
|
|
|
<h2>Decode</h2>
|
|
|
|
<input type="hidden" name="tab" value="decode" />
|
|
|
|
<label for="base64value">base64 value</label><input type="text" id="base64value" name="base64value" />
|
|
|
|
<input type="submit" method="get" value="convert"/>
|
|
|
|
</form>
|
|
|
|
<div class="result" id="decodeResult"></div>
|
|
|
|
</div>
|
2023-07-24 14:58:36 +00:00
|
|
|
<div class="tab" id="about">
|
2023-07-24 15:37:34 +00:00
|
|
|
<h2>About</h2>
|
|
|
|
<p>
|
|
|
|
This tool was made to work with <a href="https://lemmy.dbzer0.com/post/1009713">an suggestion posted by @toxictenement@lemmy.dbzer0.com</a>
|
|
|
|
by <a href="https://magmaus3.eu.org">magmaus3</a>.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
You can check the source code by downloading the page (everything is stored in a single html file),
|
|
|
|
by going to your browser's devtools or on <a href="https://codeberg.org/magmaus3/infohash2base64">Codeberg</a>.
|
|
|
|
</p>
|
2023-07-24 14:58:36 +00:00
|
|
|
</div>
|
2023-07-24 14:46:57 +00:00
|
|
|
</main>
|
2023-07-24 13:29:52 +00:00
|
|
|
</body>
|
|
|
|
</html>
|