-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl-encode.js
More file actions
36 lines (33 loc) · 1.39 KB
/
url-encode.js
File metadata and controls
36 lines (33 loc) · 1.39 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
const toolSection = document.getElementById('toolSection');
toolSection.innerHTML = `
<div class="input-area">
<label for="inputText">Text:</label>
<textarea id="inputText" rows="8" placeholder="Enter text here..."></textarea>
</div>
<div class="buttons-grid">
<button onclick="convert()" class="btn btn-primary">URL Encode</button>
<button onclick="clearAll()" class="btn btn-clear">Clear</button>
</div>
<div class="output-area">
<label for="outputText">URL Encoded:</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() {
const input = document.getElementById('inputText').value;
const encoded = encodeURIComponent(input);
document.getElementById('outputText').value = encoded;
}
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 = '';
}