need this activetime in brailletime to reset to back zero when it's done through in…
- User
need this activetime in brailletime to reset to back zero when it's done through in function activity. try fix it:
let overallStartTime = null; let isFirstGeneration = true; let brailleStartTime = Date.now(); function handleProgressBar() { const progressBarFilled = document.querySelector('.progress-bar-filled'); const currentTime = Date.now(); const normalSecondsPassed = Math.max(Math.round((currentTime - overallStartTime) / 1000) - 1, 0); const brailleSecondsPassed = Math.max(Math.round((currentTime - brailleStartTime) / 100) - 1, 0); function mapToBraille(time) { const brailleDigits = ['⠝', '⠷', '⠾', '⠄', '⠑', '⠭', '⠱', '⠚', '⠆', '⠤']; const seconds = Math.floor(time) % 1000; let brailleResult = ''; // Map seconds to braille characters const secondsString = seconds.toString().padStart(3, '0'); for (let i = 0; i < secondsString.length; i++) { const digit = parseInt(secondsString[i]); if (!isNaN(digit)) { brailleResult += brailleDigits[digit]; } } return brailleResult; } if (isGenerating) { const activeTime = normalSecondsPassed - Math.floor(normalSecondsPassed / 10); const brailleTime = mapToBraille(brailleSecondsPassed); progressBarFilled.innerHTML = brailleTime + ' ' + activeTime + ' sec'; } else { const brailleTime = mapToBraille(brailleSecondsPassed); progressBarFilled.innerHTML = '⠿⠿⠿' + ' ' + normalSecondsPassed + ' sec'; } } async function generateImage() { if (isGenerating || autoQueueActive) { return; } if (galleryArray.length >= totalLimit) { if (autoSaveEnabled) { saveAllImages().then(() => { clearGallery(); }); } else { clearGallery(); } return; } function updateProgress() { handleProgressBar(); if (isGenerating) { requestAnimationFrame(updateProgress); } } function clearGallery() { galleryArray.length = 0; updateImageCounter(); bufferContainer.innerHTML = ''; if (autoQueueActive) { generateInterval = setInterval(generateImage, interval); } } isGenerating = true; startTime = Date.now(); overallStartTime = Date.now(); updateProgress(); - Assistant
Based on the provided code, it seems like you want the
brailleStartTimeto be reset to zero whenever the functionhandleProgressBaris called through thegenerateImagefunction.To achieve this, you can add a line of code within the
generateImagefunction to reset thebrailleStartTimeto the current time. Here's the modified code:async function generateImage() { if (isGenerating || autoQueueActive) { return; } if (galleryArray.length >= totalLimit) { if (autoSaveEnabled) { saveAllImages().then(() => { clearGallery(); }); } else { clearGallery(); } return; } // Reset brailleStartTime to current time brailleStartTime = Date.now(); function updateProgress() { handleProgressBar(); if (isGenerating) { requestAnimationFrame(updateProgress); } } // Rest of the code... }By resetting
brailleStartTimeto the current time before callinghandleProgressBarwithin thegenerateImagefunction, you ensure that it starts counting from zero every time thegenerateImagefunction is triggered.