diff --git a/src/deleteMessages.js b/src/deleteMessages.js index d9ff559f..feb57ab1 100644 --- a/src/deleteMessages.js +++ b/src/deleteMessages.js @@ -152,7 +152,7 @@ async function deleteMessages(authToken, authorId, guildId, channelId, minId, ma for (let i = 0; i < messagesToDelete.length; i++) { const message = messagesToDelete[i]; - if (stopHndl && stopHndl() === false) return end(log.error('Stopped by you!')); + if (stopHndl && stopHndl()) return end(log.error('Stopped by you!')); log.debug(`${((delCount + 1) / grandTotal * 100).toFixed(2)}% (${delCount + 1}/${grandTotal})`, `Deleting ID:${redact(message.id)} ${redact(message.author.username + '#' + message.author.discriminator)} (${redact(new Date(message.timestamp).toLocaleString())}): ${redact(message.content).replace(/\n/g, '↵')}`, @@ -207,7 +207,7 @@ async function deleteMessages(authToken, authorId, guildId, channelId, minId, ma log.verb(`Searching next messages in ${searchDelay}ms...`, (offset ? `(offset: ${offset})` : '')); await wait(searchDelay); - if (stopHndl && stopHndl() === false) return end(log.error('Stopped by you!')); + if (stopHndl && stopHndl()) return end(log.error('Stopped by you!')); return await recurse(); } else { diff --git a/src/index.js b/src/index.js index e1fa29c6..cf18bc38 100644 --- a/src/index.js +++ b/src/index.js @@ -125,11 +125,12 @@ function initUI() { } -let _stopFlag; -const stopHndl = () => !(_stopFlag === true); +let _stopFlag = false; +const stopHndl = () => _stopFlag; async function start() { console.log('start'); + _stopFlag = false; // general const authToken = getToken(); @@ -160,14 +161,19 @@ async function start() { const onProg = (value, max) => { if (value && max && value > max) max = value; progress.setAttribute('max', max); - progress.value = value; - progress.style.display = max ? '' : 'none'; progress2.setAttribute('max', max); + progress.value = value; progress2.value = value; + progress.style.display = max ? '' : 'none'; progress2.style.display = max ? '' : 'none'; - percent.innerHTML = value && max ? Math.round(value / max * 100) + '%' : ''; - if (value === -1) progress.removeAttribute('value'); - if (value === -1) progress2.removeAttribute('value'); + percent.style.display = value && max ? '' : 'none'; + percent.innerHTML = value >= 0 && max ? Math.round(value / max * 100) + '%' : ''; + // indeterminate progress bar + if (value === -1) { + progress.removeAttribute('value'); + progress2.removeAttribute('value'); + percent.innerHTML = '...'; + } }; let logArea = $('#logArea'); @@ -186,8 +192,8 @@ async function start() { else if (!guildId) return logger('error', ['You must provide a Server ID!']); for (let i = 0; i < channelIds.length; i++) { - $('#start').style.display = 'none'; - $('#stop').style.display = 'block'; + $('#start').disabled = true; + $('#stop').disabled = false; await deleteMessages(authToken, authorId, guildId, channelIds[i], minId || minDate, maxId || maxDate, content, hasLink, hasFile, includeNsfw, includePinned, pattern, searchDelay, deleteDelay, logger, stopHndl, onProg); stop(); // clear the running state } @@ -196,10 +202,11 @@ async function start() { function stop() { _stopFlag = true; - $('#start').style.display = 'block'; - $('#stop').style.display = 'none'; + $('#start').disabled = false; + $('#stop').disabled = true; $('#progressBar').style.display = 'none'; + $('#progressPercent').style.display = 'none'; undiscordBtn.querySelector('progress').style.display = 'none'; }