-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode.js
23 lines (20 loc) · 934 Bytes
/
decode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const base64 = urlParams.get('base64');
var display = document.getElementById("decodedDisplay") // get the output
var space3 = document.getElementById("space3")
if (base64) { // check if there is anything in the query
console.log(base64)
var decodeThis = base64.replace(" ", "+"); // janky workaround for + becoming space
console.log(decodeThis)
decoded = decodeURIComponent(atob(decodeThis))
console.log(decoded)
var decodedReady = decoded.replace(/(\r\n|\r|\n)/g, '<br>'); // get newlines working
display.innerHTML = "<h1> Here it is! </h1> <br> <textarea class=\"textOut\" readonly>" + decodedReady + "</textarea><br><br>" // write the text
display.classList.add("decoded")
space3.innerHTML = "<br>"
display.removeAttribute("hidden")
}
else {
display.innerHTML = "" // blank if there is nothing encoded
}