@@ -2,63 +2,66 @@ import NftMC from './wasm/NftMarkerCreator_ES6_wasm.js'
2
2
3
3
const nftMC = await NftMC ( ) ;
4
4
5
- var imageLoader = document . getElementById ( 'imageLoader' ) ;
5
+ const imageLoader = document . getElementById ( 'imageLoader' ) ;
6
6
imageLoader . addEventListener ( 'change' , handleImage , false ) ;
7
- var canvas = document . getElementById ( 'imageCanvas' ) ;
8
- var hideCanvas = document . getElementById ( 'hideCanvas' ) ;
7
+
8
+ const canvas = document . getElementById ( 'imageCanvas' ) ;
9
+ const hideCanvas = document . getElementById ( 'hideCanvas' ) ;
9
10
hideCanvas . style . display = "none" ;
10
- var ctx = canvas . getContext ( '2d' ) ;
11
+
12
+ const ctx = canvas . getContext ( '2d' ) ;
11
13
ctx . fillStyle = "#949494" ;
12
14
ctx . fillRect ( 0 , 0 , canvas . width , canvas . height ) ;
13
- var ctxHide = hideCanvas . getContext ( '2d' ) ;
14
15
15
- var reader = new FileReader ( ) ;
16
+ const ctxHide = hideCanvas . getContext ( '2d' ) ;
17
+
18
+ const reader = new FileReader ( ) ;
16
19
17
- var name ;
18
- var nameWithExt ;
20
+ let name ;
21
+ let nameWithExt ;
19
22
20
- var globalObj = {
23
+ const globalObj = {
21
24
dpi : 0 ,
22
25
nc : 0 ,
23
26
w : 0 ,
24
27
h : 0 ,
25
28
arr : [ ]
26
- }
29
+ } ;
27
30
28
31
function handleImage ( e ) {
29
32
nameWithExt = e . target . files [ 0 ] . name ;
30
33
console . log ( "Image uploaded: " + nameWithExt ) ;
31
34
32
- name = nameWithExt . substr ( 0 , nameWithExt . lastIndexOf ( '.' ) ) ;
35
+ name = nameWithExt . substring ( 0 , nameWithExt . lastIndexOf ( '.' ) ) ;
33
36
34
- let extJpg = nameWithExt . substr ( nameWithExt . lastIndexOf ( '.' ) ) ;
37
+ let extJpg = nameWithExt . substring ( nameWithExt . lastIndexOf ( '.' ) ) ;
35
38
36
39
let confidenceEl = document . getElementById ( "confidenceLevel" ) ;
37
40
let childEls = confidenceEl . getElementsByClassName ( "confidenceEl" ) ;
38
41
for ( let i = 0 ; i < childEls . length ; i ++ ) {
39
42
childEls [ i ] . src = "./icons/star2.svg" ;
40
43
}
41
44
42
- if ( extJpg == '.jpg' || extJpg == '.jpeg' || extJpg == '.JPG' || extJpg == '.JPEG' ) {
45
+ if ( extJpg === '.jpg' || extJpg === '.jpeg' || extJpg === '.JPG' || extJpg = == '.JPEG' ) {
43
46
useJpeg ( e ) ;
44
- } else if ( extJpg == '.png' || extJpg == '.PNG' ) {
47
+ } else if ( extJpg === '.png' || extJpg = == '.PNG' ) {
45
48
globalObj . dpi = 72 ;
46
49
readImage ( e )
47
50
} else {
48
- console . log ( "Invalid image format!" ) ;
51
+ console . error ( "Invalid image format!" ) ;
49
52
}
50
53
51
54
document . getElementById ( "generateBt" ) . disabled = false ;
52
55
}
53
56
54
57
function generate ( ) {
55
- var imageCanvas = document . querySelector ( '#imageCanvas' ) ;
58
+ const imageCanvas = document . querySelector ( '#imageCanvas' ) ;
56
59
imageCanvas . style . opacity = 0.25 ;
57
60
58
- var okSign = document . querySelector ( '.checkmark-cover' ) ;
61
+ const okSign = document . querySelector ( '.checkmark-cover' ) ;
59
62
okSign . style . display = 'none' ;
60
63
61
- var spinner = document . querySelector ( '.spinner-container' ) ;
64
+ const spinner = document . querySelector ( '.spinner-container' ) ;
62
65
spinner . style . display = 'block' ;
63
66
64
67
setTimeout ( ( ) => {
@@ -86,48 +89,48 @@ function downloadIset() {
86
89
let ext2 = ".fset" ;
87
90
let ext3 = ".fset3" ;
88
91
89
- let content = nftMC . FS . readFile ( filenameIset , { flags : 'r+' } ) ;
90
- let contentFset = nftMC . FS . readFile ( filenameFset , { flags : 'r+' } ) ;
91
- let contentFset3 = nftMC . FS . readFile ( filenameFset3 , { flags : 'r+' } ) ;
92
+ let content = nftMC . FS . readFile ( filenameIset ) ;
93
+ let contentFset = nftMC . FS . readFile ( filenameFset ) ;
94
+ let contentFset3 = nftMC . FS . readFile ( filenameFset3 ) ;
92
95
93
- var a = document . createElement ( 'a' ) ;
94
- a . download = name + ext ;
95
- a . href = URL . createObjectURL ( new Blob ( [ content ] , { type : mime } ) ) ;
96
- a . style . display = 'none' ;
96
+ const isetFile = document . createElement ( 'a' ) ;
97
+ isetFile . download = name + ext ;
98
+ isetFile . href = URL . createObjectURL ( new Blob ( [ content ] , { type : mime } ) ) ;
99
+ isetFile . style . display = 'none' ;
97
100
98
- var b = document . createElement ( 'a' ) ;
99
- b . download = name + ext2 ;
100
- b . href = URL . createObjectURL ( new Blob ( [ contentFset ] , { type : mime } ) ) ;
101
- b . style . display = 'none' ;
101
+ const fsetFile = document . createElement ( 'a' ) ;
102
+ fsetFile . download = name + ext2 ;
103
+ fsetFile . href = URL . createObjectURL ( new Blob ( [ contentFset ] , { type : mime } ) ) ;
104
+ fsetFile . style . display = 'none' ;
102
105
103
- var c = document . createElement ( 'a' ) ;
104
- c . download = name + ext3 ;
105
- c . href = URL . createObjectURL ( new Blob ( [ contentFset3 ] , { type : mime } ) ) ;
106
- c . style . display = 'none' ;
106
+ const fset3File = document . createElement ( 'a' ) ;
107
+ fset3File . download = name + ext3 ;
108
+ fset3File . href = URL . createObjectURL ( new Blob ( [ contentFset3 ] , { type : mime } ) ) ;
109
+ fset3File . style . display = 'none' ;
107
110
108
- document . body . appendChild ( a ) ;
109
- a . click ( ) ;
111
+ document . body . appendChild ( isetFile ) ;
112
+ isetFile . click ( ) ;
110
113
111
- document . body . appendChild ( b ) ;
112
- b . click ( ) ;
114
+ document . body . appendChild ( fsetFile ) ;
115
+ fsetFile . click ( ) ;
113
116
114
- document . body . appendChild ( c ) ;
115
- c . click ( ) ;
117
+ document . body . appendChild ( fset3File ) ;
118
+ fset3File . click ( ) ;
116
119
117
- var spinner = document . querySelector ( '.spinner-container' ) ;
120
+ const spinner = document . querySelector ( '.spinner-container' ) ;
118
121
spinner . style . display = 'none' ;
119
122
120
- var okSign = document . querySelector ( '.checkmark-cover' ) ;
123
+ const okSign = document . querySelector ( '.checkmark-cover' ) ;
121
124
okSign . style . display = 'block' ;
122
125
}
123
126
124
127
function getUint8 ( str ) {
125
- let base64 = str . substr ( 23 , str . length ) ;
126
- var raw = atob ( base64 ) ;
127
- var rawLength = raw . length ;
128
- var array = new Uint8Array ( new ArrayBuffer ( rawLength ) ) ;
128
+ const base64 = str . substring ( 23 ) ;
129
+ const raw = atob ( base64 ) ;
130
+ const rawLength = raw . length ;
131
+ const array = new Uint8Array ( new ArrayBuffer ( rawLength ) ) ;
129
132
130
- for ( i = 0 ; i < rawLength ; i ++ ) {
133
+ for ( let i = 0 ; i < rawLength ; i ++ ) {
131
134
array [ i ] = raw . charCodeAt ( i ) ;
132
135
}
133
136
@@ -162,12 +165,12 @@ function detectColorSpace(arr) {
162
165
let g = arr [ j + 1 ] ;
163
166
let b = arr [ j + 2 ] ;
164
167
165
- if ( r == g && r == b ) {
168
+ if ( r === g && r = == b ) {
166
169
counter ++ ;
167
170
}
168
171
}
169
172
170
- if ( target == counter ) {
173
+ if ( target === counter ) {
171
174
return 1 ;
172
175
} else {
173
176
return 3 ;
@@ -184,10 +187,10 @@ function useJpeg(e) {
184
187
globalObj . dpi = dpi1 ;
185
188
}
186
189
187
- var nc1 = EXIF . getTag ( this , "ComponentsConfiguration" )
190
+ const nc1 = EXIF . getTag ( this , "ComponentsConfiguration" ) ;
188
191
189
192
if ( isNaN ( nc1 ) || nc1 == null ) {
190
- var nc2 = parseFloat ( EXIF . getTag ( this , "SamplesPerPixel" ) ) ;
193
+ const nc2 = parseFloat ( EXIF . getTag ( this , "SamplesPerPixel" ) ) ;
191
194
if ( isNaN ( nc2 ) || nc2 == null ) {
192
195
// openModal();
193
196
} else {
@@ -222,17 +225,17 @@ function readImage(e) {
222
225
ctx . drawImage ( img , 0 , 0 , img . width , img . height , // source rectangle
223
226
0 , 0 , canvas . width , canvas . height ) ; // destination rectangle
224
227
225
- var imgData = ctxHide . getImageData ( 0 , 0 , hideCanvas . width , hideCanvas . height ) ;
228
+ const imgData = ctxHide . getImageData ( 0 , 0 , hideCanvas . width , hideCanvas . height ) ;
226
229
227
230
let newArr = [ ] ;
228
231
229
232
let verifyColorSpace = detectColorSpace ( imgData . data ) ;
230
233
231
- if ( verifyColorSpace == 1 ) {
234
+ if ( verifyColorSpace === 1 ) {
232
235
for ( let j = 0 ; j < imgData . data . length ; j += 4 ) {
233
236
newArr . push ( imgData . data [ j ] ) ;
234
237
}
235
- } else if ( verifyColorSpace == 3 ) {
238
+ } else if ( verifyColorSpace === 3 ) {
236
239
for ( let j = 0 ; j < imgData . data . length ; j += 4 ) {
237
240
newArr . push ( imgData . data [ j ] ) ;
238
241
newArr . push ( imgData . data [ j + 1 ] ) ;
@@ -242,9 +245,7 @@ function readImage(e) {
242
245
243
246
globalObj . nc = verifyColorSpace ;
244
247
245
- let uint = new Uint8Array ( newArr ) ;
246
-
247
- globalObj . arr = uint ;
248
+ globalObj . arr = new Uint8Array ( newArr ) ;
248
249
249
250
let confidence = calculateQuality ( ) ;
250
251
let confidenceEl = document . getElementById ( "confidenceLevel" ) ;
0 commit comments