|
83 | 83 | } |
84 | 84 |
|
85 | 85 | function resetOutput() { |
86 | | - hintLabel.textContent = 'Enter a secret and select an image file to encode / decode.'; |
87 | 86 | inputImgDiv.innerHTML = ''; |
88 | 87 | outputDiv.innerHTML = ''; |
89 | 88 | errorDiv.textContent = ''; |
90 | 89 | errorDiv.style.display = 'none'; |
91 | 90 | downloadBtn.style.display = 'none'; |
| 91 | + hintLabel.textContent = 'Enter a secret and select an image file to encode / decode.'; |
92 | 92 | } |
93 | 93 |
|
94 | 94 | async function showImage(imBlob) { |
|
116 | 116 | async function encode_image() { |
117 | 117 | checkInput(); |
118 | 118 | resetOutput(); |
119 | | - |
120 | 119 | const inputBlob = await getInputBlob(); |
121 | | - |
122 | 120 | hintLabel.textContent = `Encoding...`; |
123 | | - |
124 | 121 | worker.postMessage({type: 'encode', buffer: inputBlob, secret: secretInput.value }); |
125 | | - worker.onmessage = async (event) => { |
126 | | - if (event.data.error) { |
127 | | - await showError(`Error encoding: ${event.data.error}`); |
128 | | - console.error(event.data.error); |
129 | | - return; |
130 | | - } |
131 | | - const outputBlob = event.data.buffer; |
132 | | - await showImage(outputBlob); |
133 | | - }; |
134 | | - |
135 | 122 | } |
136 | 123 |
|
137 | 124 | async function decode_image() { |
138 | 125 | checkInput(); |
139 | 126 | resetOutput(); |
140 | | - |
141 | 127 | const inputBlob = await getInputBlob(); |
142 | | - |
143 | 128 | hintLabel.textContent = `Decoding...`; |
144 | | - |
145 | | - let outputBlob; |
146 | 129 | worker.postMessage({type: 'decode', buffer: inputBlob, secret: secretInput.value }); |
147 | | - worker.onmessage = async (event) => { |
148 | | - if (event.data.error) { |
149 | | - await showError(`Error decoding: ${event.data.error}`); |
150 | | - console.error(event.data.error); |
151 | | - return; |
152 | | - } |
153 | | - outputBlob = event.data.buffer; |
154 | | - await showImage(outputBlob); |
155 | | - }; |
156 | 130 | } |
157 | 131 |
|
| 132 | + worker.onmessage = async (event) => { |
| 133 | + if (event.data.error) { |
| 134 | + await showError(`Error decoding: ${event.data.error}`); |
| 135 | + console.error(event.data.error); |
| 136 | + return; |
| 137 | + } |
| 138 | + await showImage(event.data.buffer); |
| 139 | + }; |
| 140 | + |
158 | 141 | encodeButton.addEventListener('click', encode_image); |
159 | 142 | decodeButton.addEventListener('click', decode_image); |
160 | 143 | fileInput.addEventListener('change', ()=>{ |
|
0 commit comments