From d86a6370a078fdb900b79da7ab50f90690e950ea Mon Sep 17 00:00:00 2001 From: sup39 Date: Sat, 8 Apr 2023 10:24:52 +0900 Subject: [PATCH] Add timestamp to saved png file name --- piano-visualizer.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/piano-visualizer.js b/piano-visualizer.js index d16b303..ca9b8ee 100644 --- a/piano-visualizer.js +++ b/piano-visualizer.js @@ -221,7 +221,17 @@ function truncateString(str, maxLength = 40) { function mouseClicked() { // Save the canvas content as an image file if (mouseX < 50 && mouseY < 50) { - saveCanvas('nicechord-pianometer', 'png'); + const now = new Date(); + const strDate = + now.getFullYear() + + String(now.getMonth()+1).padStart(2, '0') + + String(now.getDate()).padStart(2, '0'); + const strTime = + String(now.getHours()).padStart(2, '0') + + String(now.getMinutes()).padStart(2, '0') + + String(now.getSeconds()).padStart(2, '0'); + const fileName = `nicechord-pianometer-${strDate}_${strTime}`; + saveCanvas(fileName, 'png'); } if (mouseY > 76) { if (mouseX <= 84) { @@ -245,4 +255,4 @@ function mouseClicked() { } } console.log(mouseX, mouseY); -} \ No newline at end of file +}