-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64-decode.js
More file actions
40 lines (37 loc) · 1.55 KB
/
base64-decode.js
File metadata and controls
40 lines (37 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const toolSection = document.getElementById('toolSection');
toolSection.innerHTML = `
<div class="input-area">
<label for="inputText">Base64:</label>
<textarea id="inputText" rows="8" placeholder="Enter text here..."></textarea>
</div>
<div class="buttons-grid">
<button onclick="convert()" class="btn btn-primary">Decode from Base64</button>
<button onclick="clearAll()" class="btn btn-clear">Clear</button>
</div>
<div class="output-area">
<label for="outputText">Decoded Text:</label>
<textarea id="outputText" rows="8" readonly placeholder="Result will appear here..."></textarea>
<button onclick="copyOutput()" class="btn btn-copy" id="copyBtn">📋 Copy</button>
</div>
`;
function convert() {
try {
const input = document.getElementById('inputText').value;
const decoded = decodeURIComponent(escape(atob(input)));
document.getElementById('outputText').value = decoded;
} catch(e) {
document.getElementById('outputText').value = 'Error: Invalid Base64 input';
}
}
function copyOutput() {
const output = document.getElementById('outputText');
if (!output.value) return;
navigator.clipboard.writeText(output.value).then(() => {
document.getElementById('copyBtn').textContent = '✅ Copied!';
setTimeout(() => { document.getElementById('copyBtn').textContent = '📋 Copy'; }, 2000);
});
}
function clearAll() {
document.getElementById('inputText').value = '';
document.getElementById('outputText').value = '';
}