@@ -4,8 +4,7 @@ window.shark = window.shark || {};
4
4
5
5
window . shark . info = window . shark . info || { } ;
6
6
window . shark . screenshots = window . shark . screenshots || { } ;
7
-
8
- var screenshot_counter = 0 ;
7
+ window . shark . screenshot_counter = 0 ;
9
8
10
9
function goToLoadingScreen ( ) {
11
10
document . querySelector ( '.file-upload-screen' ) . style . display = 'none' ;
@@ -244,12 +243,12 @@ function addScreenshot(screenshot) {
244
243
</div>
245
244
<div>
246
245
<span>
247
- <button onclick='flipScreenshot("${ screenshot . id } ", axis= "x")'>Vertical Flip</button>
248
- <button onclick='flipScreenshot("${ screenshot . id } ", axis= "y")'>Horizontal Flip</button>
246
+ <button onclick='flipScreenshot("${ screenshot . id } ", "x")'>Vertical Flip</button>
247
+ <button onclick='flipScreenshot("${ screenshot . id } ", "y")'>Horizontal Flip</button>
249
248
</span>
250
249
</div>
251
250
<div>
252
- <button onclick='delete_screenshot ("${ screenshot . id } ")'>Delete</button>
251
+ <button onclick='deleteScreenshot ("${ screenshot . id } ")'>Delete</button>
253
252
</div>
254
253
</div>
255
254
</div>
@@ -259,7 +258,7 @@ function addScreenshot(screenshot) {
259
258
}
260
259
261
260
// Flip a screenshot by adding it the the canvas flipped horizontally or vertically.
262
- function flipScreenshot ( screenshot_id , axis = 'y' ) {
261
+ function flipScreenshot ( screenshot_id , axis ) {
263
262
// Find correct image, add to canvas to flip.
264
263
let img = document . querySelector ( `.screenshot[data-id="${ screenshot_id } "] img` ) ;
265
264
@@ -268,31 +267,25 @@ function flipScreenshot(screenshot_id, axis='y') {
268
267
canvas . height = img . naturalHeight ;
269
268
270
269
let context = canvas . getContext ( '2d' ) ;
271
-
272
- // Horizontal flip.
270
+
271
+ let direction = ''
273
272
if ( axis === 'y' ) {
273
+ direction = 'flipped_horizontally' ;
274
274
context . scale ( - 1 , 1 ) ;
275
275
context . drawImage ( img , - img . naturalWidth , 0 ) ;
276
-
277
- // Draw the canvas to the image area.
278
- img . src = canvas . toDataURL ( 'image/jpeg' ) ;
279
-
280
- // Update image metadata.
281
- window . shark . screenshots [ screenshot_id ] [ 'flipped_horizontally' ] = ! Boolean ( window . shark . screenshots [ screenshot_id ] [ 'flipped_horizontally' ] ) ;
282
- }
283
-
284
- // Vertical flip.
285
- if ( axis === 'x' ) {
276
+ } else if ( axis === 'x' ) {
277
+ direction = 'flipped_vertically' ;
286
278
context . scale ( 1 , - 1 ) ;
287
279
context . drawImage ( img , 0 , - img . naturalHeight ) ;
280
+ } else {
281
+ throw ( "Invalid flip axis." )
282
+ }
288
283
289
- // Draw the canvas to the image area.
290
- img . src = canvas . toDataURL ( 'image/jpeg' ) ;
284
+ // Draw the canvas to the image area.
285
+ img . src = canvas . toDataURL ( 'image/jpeg' ) ;
291
286
292
- // Update image metadata.
293
- window . shark . screenshots [ screenshot_id ] [ 'flipped_vertically' ] = ! Boolean ( window . shark . screenshots [ screenshot_id ] [ 'flipped_vertically' ] ) ;
294
- }
295
-
287
+ // Update image metadata.
288
+ window . shark . screenshots [ screenshot_id ] [ direction ] = ! Boolean ( window . shark . screenshots [ screenshot_id ] [ direction ] ) ;
296
289
window . shark . screenshots [ screenshot_id ] [ 'dataURL' ] = canvas . toDataURL ( 'image/jpeg' ) ;
297
290
}
298
291
@@ -364,8 +357,8 @@ function takeVideoScreenshot(query, xPercent, yPercent, widthPercent, heightPerc
364
357
let id = randomHex ( ) ;
365
358
366
359
// Get screenshot counter value and update counter.
367
- let index_string = String ( screenshot_counter ) . padStart ( 3 , '0' ) ;
368
- screenshot_counter += 1 ;
360
+ let index_string = String ( window . shark . screenshot_counter ) . padStart ( 3 , '0' ) ;
361
+ window . shark . screenshot_counter ++ ;
369
362
370
363
let name = window . shark . info [ 'video' ] . name + "_" + index_string ;
371
364
@@ -404,12 +397,11 @@ function takeScreenshot(source, x, y, width, height, format = 'image/jpeg') {
404
397
return canvas . toDataURL ( format ) ;
405
398
}
406
399
407
- // Delete a screenshot, it is no longer displayed or saved.
408
- function delete_screenshot ( screenshot_id ) {
400
+ function deleteScreenshot ( screenshot_id ) {
409
401
// Find screenshot area to remove.
410
402
let screenshot_area = document . querySelector ( `.screenshot[data-id="${ screenshot_id } "]` ) ;
411
403
screenshot_area . remove ( ) ;
412
- // Update screenshots metadata to remove flipped image.
404
+
413
405
delete window . shark . screenshots [ screenshot_id ] ;
414
406
}
415
407
0 commit comments