Skip to content

Commit f06a976

Browse files
committed
Delete button with new screenshot counter
1 parent a6a4686 commit f06a976

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

static/js/main.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ window.shark = window.shark || {};
55
window.shark.info = window.shark.info || {};
66
window.shark.screenshots = window.shark.screenshots || {};
77

8+
var screenshot_counter = 0;
9+
810
function goToLoadingScreen() {
911
document.querySelector('.file-upload-screen').style.display = 'none';
1012
document.querySelector('.loading-screen').style.display = 'initial';
@@ -246,6 +248,9 @@ function addScreenshot(screenshot) {
246248
<button onclick='flipScreenshot("${screenshot.id}", axis="y")'>Horizontal Flip</button>
247249
</span>
248250
</div>
251+
<div>
252+
<button onclick='delete_screenshot("${screenshot.id}")'>Delete</button>
253+
</div>
249254
</div>
250255
</div>
251256
`;
@@ -358,7 +363,10 @@ function takeVideoScreenshot(query, xPercent, yPercent, widthPercent, heightPerc
358363

359364
let id = randomHex();
360365

361-
let index_string = String(Object.keys(window.shark.screenshots).length).padStart(3, '0');
366+
// Get screenshot counter value and update counter.
367+
let index_string = String(screenshot_counter).padStart(3, '0');
368+
screenshot_counter += 1;
369+
362370
let name = window.shark.info['video'].name + "_" + index_string;
363371

364372
let time = undefined;
@@ -396,6 +404,15 @@ function takeScreenshot(source, x, y, width, height, format = 'image/jpeg') {
396404
return canvas.toDataURL(format);
397405
}
398406

407+
// Delete a screenshot, it is no longer displayed or saved.
408+
function delete_screenshot(screenshot_id) {
409+
// Find screenshot area to remove.
410+
let screenshot_area = document.querySelector(`.screenshot[data-id="${screenshot_id}"]`);
411+
screenshot_area.remove();
412+
// Update screenshots metadata to remove flipped image.
413+
delete window.shark.screenshots[screenshot_id];
414+
}
415+
399416
// Inputs don't have a timezone aware type.
400417
// Instead we use datetime-local (which is always local).
401418
// But to format to set it's input is a bit tricky to set (while getting the timezone correct).

0 commit comments

Comments
 (0)