@@ -26,12 +26,16 @@ const footer = document.getElementById('footer');
2626
2727const worker = new Worker ( './worker.js' , { type : 'module' } ) ;
2828
29+ const Mode = Object . freeze ( {
30+ CRYPTO : 'crypto' ,
31+ STEGANO : 'stegano'
32+ } ) ;
2933function onModeChange ( mode ) {
30- if ( mode === 'crypto' ) {
34+ if ( mode === Mode . CRYPTO ) {
3135 msgInputContainer . style . display = 'none' ;
3236 imTypeSelect . disabled = false ;
3337 imTypeContainer . style . display = 'block' ;
34- } else if ( mode === 'stegano' ) {
38+ } else if ( mode === Mode . STEGANO ) {
3539 msgInputContainer . style . display = 'flex' ;
3640 imTypeSelect . value = 'png' ;
3741 imTypeSelect . dispatchEvent ( new Event ( 'change' ) ) ;
@@ -60,24 +64,24 @@ function onModeChange(mode) {
6064 case 'steganography' :
6165 cipherModeInput . checked = false ;
6266 steganoModeInput . checked = true ;
63- onModeChange ( 'stegano' ) ;
67+ onModeChange ( Mode . STEGANO ) ;
6468 break ;
6569 case 'cipher' :
6670 case 'crypto' :
6771 case 'cryptography' :
6872 default :
6973 cipherModeInput . checked = true ;
7074 steganoModeInput . checked = false ;
71- onModeChange ( 'crypto' ) ;
75+ onModeChange ( Mode . CRYPTO ) ;
7276 break ;
7377 }
7478}
7579
7680function getMode ( ) {
7781 if ( cipherModeInput . checked ) {
78- return 'crypto' ;
82+ return Mode . CRYPTO ;
7983 } else if ( steganoModeInput . checked ) {
80- return 'stegano' ;
84+ return Mode . STEGANO ;
8185 }
8286 throw new Error ( "No mode selected" ) ;
8387}
@@ -93,11 +97,9 @@ function checkInputRaise() {
9397 showError ( "No image file selected" ) ;
9498 throw new Error ( "No image file selected" ) ;
9599 }
96- if ( secretInput . value . trim ( ) === '' ) {
97- if ( getMode ( ) === 'crypto' ) {
98- showError ( "Secret cannot be empty" ) ;
99- throw new Error ( "Secret cannot be empty" ) ;
100- }
100+ if ( secretInput . value . trim ( ) === '' && getMode ( ) === Mode . CRYPTO ) {
101+ showError ( "Secret cannot be empty" ) ;
102+ throw new Error ( "Secret cannot be empty" ) ;
101103 }
102104}
103105
@@ -158,7 +160,7 @@ async function encode_image() {
158160
159161 ensureOutput ( ) ;
160162 switch ( getMode ( ) ) {
161- case 'crypto' :
163+ case Mode . CRYPTO :
162164 worker . postMessage ( {
163165 type : 'encode' ,
164166 buffer : inputBlob ,
@@ -167,7 +169,7 @@ async function encode_image() {
167169 outputAs : imTypeSelect . value
168170 } ) ;
169171 break ;
170- case 'stegano' :
172+ case Mode . STEGANO :
171173 worker . postMessage ( {
172174 type : 'stega_encode' ,
173175 buffer : inputBlob ,
@@ -190,7 +192,7 @@ async function decode_image() {
190192
191193 ensureOutput ( ) ;
192194 switch ( getMode ( ) ) {
193- case 'crypto' :
195+ case Mode . CRYPTO :
194196 worker . postMessage ( {
195197 type : 'decode' ,
196198 buffer : inputBlob ,
@@ -199,7 +201,7 @@ async function decode_image() {
199201 outputAs : imTypeSelect . value
200202 } ) ;
201203 break ;
202- case 'stegano' :
204+ case Mode . STEGANO :
203205 worker . postMessage ( {
204206 type : 'stega_decode' ,
205207 buffer : inputBlob ,
@@ -234,6 +236,7 @@ worker.onmessage = async (event) => {
234236 messageElem . textContent = event . data . message ;
235237 outputDiv . appendChild ( messageElem ) ;
236238 messageElem . style . whiteSpace = 'pre-wrap' ;
239+ messageElem . style . wordBreak = 'break-all' ;
237240 downloadBtnContainer . style . display = 'none' ;
238241 }
239242} ;
@@ -245,12 +248,12 @@ worker.onmessage = async (event) => {
245248
246249 steganoModeInput . addEventListener ( 'change' , ( ) => {
247250 if ( steganoModeInput . checked ) {
248- onModeChange ( 'stegano' ) ;
251+ onModeChange ( Mode . STEGANO ) ;
249252 }
250253 } )
251254 cipherModeInput . addEventListener ( 'change' , ( ) => {
252255 if ( cipherModeInput . checked ) {
253- onModeChange ( 'crypto' ) ;
256+ onModeChange ( Mode . CRYPTO ) ;
254257 }
255258 } )
256259
0 commit comments