-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl-encoder.html
More file actions
156 lines (135 loc) · 5.51 KB
/
url-encoder.html
File metadata and controls
156 lines (135 loc) · 5.51 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Encoder/Decoder</title>
<link rel="stylesheet" href="common.css">
<style>
body {
display: flex;
flex-direction: column;
}
</style>
</head>
<body>
<a href="index.html" class="back-link">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M19 12H5M12 19l-7-7 7-7"/>
</svg>
All Tools
</a>
<header>
<h1>URL Encoder/Decoder</h1>
<p class="subtitle">Real-time bidirectional conversion</p>
</header>
<div class="controls">
<button id="clearBtn" class="secondary">Clear All</button>
</div>
<div class="container">
<div class="pane">
<div class="pane-header">
<span class="label">
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
</svg>
Decoded Text
</span>
<button id="copyDecoded" class="copy-btn">Copy</button>
</div>
<textarea id="decodedArea" placeholder="Type or paste decoded text here..." spellcheck="false"></textarea>
</div>
<div class="pane">
<div class="pane-header">
<span class="label">
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path>
<path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path>
</svg>
URL Encoded
<span id="statusIndicator" class="status-indicator"></span>
</span>
<button id="copyEncoded" class="copy-btn">Copy</button>
</div>
<textarea id="encodedArea" placeholder="Type or paste URL encoded text here..." spellcheck="false"></textarea>
<div id="errorMessage" class="error-message"></div>
</div>
</div>
<script>
const decodedArea = document.getElementById('decodedArea');
const encodedArea = document.getElementById('encodedArea');
const clearBtn = document.getElementById('clearBtn');
const copyDecoded = document.getElementById('copyDecoded');
const copyEncoded = document.getElementById('copyEncoded');
const errorMessage = document.getElementById('errorMessage');
const statusIndicator = document.getElementById('statusIndicator');
let updating = false;
function encodeText() {
if (updating) return;
updating = true;
errorMessage.style.display = 'none';
statusIndicator.className = 'status-indicator';
const text = decodedArea.value;
if (!text) {
encodedArea.value = '';
updating = false;
return;
}
try {
encodedArea.value = encodeURIComponent(text);
statusIndicator.className = 'status-indicator valid';
} catch (e) {
statusIndicator.className = 'status-indicator invalid';
}
updating = false;
}
function decodeText() {
if (updating) return;
updating = true;
errorMessage.style.display = 'none';
statusIndicator.className = 'status-indicator';
const encoded = encodedArea.value;
if (!encoded) {
decodedArea.value = '';
updating = false;
return;
}
try {
decodedArea.value = decodeURIComponent(encoded);
statusIndicator.className = 'status-indicator valid';
} catch (e) {
errorMessage.style.display = 'block';
errorMessage.textContent = 'Invalid URL encoded string';
statusIndicator.className = 'status-indicator invalid';
}
updating = false;
}
decodedArea.addEventListener('input', encodeText);
encodedArea.addEventListener('input', decodeText);
clearBtn.addEventListener('click', () => {
decodedArea.value = '';
encodedArea.value = '';
errorMessage.style.display = 'none';
statusIndicator.className = 'status-indicator';
decodedArea.focus();
});
function setupCopyButton(btn, textarea) {
btn.addEventListener('click', () => {
if (!textarea.value) return;
navigator.clipboard.writeText(textarea.value).then(() => {
const originalText = btn.textContent;
btn.textContent = 'Copied!';
btn.classList.add('copied');
setTimeout(() => {
btn.textContent = originalText;
btn.classList.remove('copied');
}, 2000);
});
});
}
setupCopyButton(copyDecoded, decodedArea);
setupCopyButton(copyEncoded, encodedArea);
</script>
</body>
</html>