Skip to content

Commit 181c623

Browse files
committed
Show component encoding/decoding only if it's different
1 parent 36d24c7 commit 181c623

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@
6969
<td>URI Encoding</td>
7070
<td id="uri_encoded_out"></td>
7171
</tr>
72-
<tr>
72+
<tr id="uri_component_encoding_row">
7373
<td>Component Encoding</td>
7474
<td id="uri_component_encoded_out"></td>
7575
</tr>
7676
<tr>
7777
<td>URI Decoding</td>
7878
<td id="uri_decoded_out"></td>
7979
</tr>
80-
<tr>
80+
<tr id="uri_component_decoding_row">
8181
<td>Component Decoding</td>
8282
<td id="uri_component_decoded_out"></td>
8383
</tr>

js/script.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,26 @@ function calculateAndPopulate(input) {
5757
const uri_encoding = uriEncode(input);
5858
setElementContentById("uri_encoded_out", uri_encoding);
5959

60+
// Only show component encoding if it's different from regular encoding
6061
const uri_component_encoding = uriEncodeComponent(input);
61-
setElementContentById("uri_component_encoded_out", uri_component_encoding);
62+
if (uri_component_encoding !== uri_encoding) {
63+
showElement("uri_component_encoding_row");
64+
setElementContentById("uri_component_encoded_out", uri_component_encoding);
65+
} else {
66+
hideElement("uri_component_encoding_row");
67+
}
6268

6369
const uri_decoding = uriDecode(input);
6470
setElementContentById("uri_decoded_out", uri_decoding);
6571

72+
// Only show component decoding if it's different from regular decoding
6673
const uri_component_decoding = uriDecodeComponent(input);
67-
setElementContentById("uri_component_decoded_out", uri_component_decoding);
74+
if (uri_component_decoding !== uri_decoding) {
75+
showElement("uri_component_decoding_row");
76+
setElementContentById("uri_component_decoded_out", uri_component_decoding);
77+
} else {
78+
hideElement("uri_component_decoding_row");
79+
}
6880

6981
// Add character table to DOM
7082
character_table.innerHTML = characterTable(input);
@@ -79,6 +91,16 @@ async function setElementContentByIdAsync(id, promise) {
7991
setElementContentById(id, result || "");
8092
}
8193

94+
// Show/hide elements
95+
function showElement(id) {
96+
const element = document.getElementById(id);
97+
if (element) element.style.display = "";
98+
}
99+
function hideElement(id) {
100+
const element = document.getElementById(id);
101+
if (element) element.style.display = "none";
102+
}
103+
82104
// Hashing
83105
async function hashMessage(message, algorithm) {
84106
if (algorithm === "MD5") {

0 commit comments

Comments
 (0)