|
9 | 9 | <body> |
10 | 10 | <title>Image encoder</title> |
11 | 11 |
|
12 | | - <div id="input-container"> |
| 12 | + <div id="input-container" class="container"> |
13 | 13 | <div id="secret-container"> |
14 | 14 | <div id="drop-zone" style="display: none;"> |
15 | 15 | <p>Drag and drop an image file here.</p> |
16 | 16 | <p>Supported formats: PNG, JPEG, BMP, ...</p> |
17 | 17 | </div> |
18 | 18 |
|
19 | | - <label>Select an image file.</label> |
| 19 | + <label>Select an image file</label> |
20 | 20 | <input type="file" id="fileInput" accept="image/*" required> |
21 | 21 | <br> |
22 | 22 | <label for="secretInput">Secret:</label> |
|
36 | 36 | </div> |
37 | 37 | </div> |
38 | 38 |
|
39 | | - <div id="output-container"> |
40 | | - <div id="downloadBtnContainer"> |
41 | | - <button id="downloadBtn" style="display: none;">Download Image</button> |
| 39 | + <div id="output-container" class="container"> |
| 40 | + <div id="error"></div> |
| 41 | + <div id="downloadBtnContainer" style="display: none"> |
| 42 | + <button id="downloadBtn">Download Image</button> |
42 | 43 | </div> |
43 | | - <label id="hint">Enter a secret and select an image file to encode / decode.</label> |
| 44 | + <label id="hint">Enter a secret and select an image file to encode / decode</label> |
44 | 45 | <div id="inputImg"></div> |
45 | 46 | <div id="output"></div> |
46 | | - <div id="error"></div> |
47 | 47 | </div> |
48 | 48 |
|
49 | 49 | <div id="footer"> |
|
71 | 71 | const hintLabel = document.getElementById('hint'); |
72 | 72 | const encodeButton = document.getElementById('encodeButton'); |
73 | 73 | const decodeButton = document.getElementById('decodeButton'); |
| 74 | + const downloadBtnContainer = document.getElementById('downloadBtnContainer'); |
74 | 75 | const downloadBtn = document.getElementById('downloadBtn'); |
75 | 76 | const errorDiv = document.getElementById('error'); |
76 | 77 | const worker = new Worker('./worker.js', { type: 'module' }); |
|
109 | 110 | outputDiv.innerHTML = ''; |
110 | 111 | errorDiv.textContent = ''; |
111 | 112 | errorDiv.style.display = 'none'; |
112 | | - downloadBtn.style.display = 'none'; |
113 | | - hintLabel.textContent = 'Enter a secret and select an image file to encode / decode.'; |
| 113 | + downloadBtnContainer.style.display = 'none'; |
| 114 | + hintLabel.textContent = 'Enter a secret and select an image file to encode / decode'; |
114 | 115 | } |
115 | 116 |
|
116 | 117 | async function showImage(imBlob) { |
|
124 | 125 | imgElem.alt = 'Image'; |
125 | 126 | outputDiv.appendChild(imgElem); |
126 | 127 |
|
127 | | - downloadBtn.style.display = 'block'; |
| 128 | + downloadBtnContainer.style.display = 'block'; |
128 | 129 | downloadBtn.onclick = () => { |
129 | 130 | const a = document.createElement('a'); |
130 | 131 | a.href = url; |
131 | | - a.download = 'image.png'; |
| 132 | + const timeName = new Date().toISOString().replace(/[:.]/g, '-'); |
| 133 | + a.download = `img-${timeName}.png`; |
132 | 134 | document.body.appendChild(a); |
133 | 135 | a.click(); |
134 | 136 | document.body.removeChild(a); |
|
0 commit comments