Skip to content

Commit

Permalink
fixing stop button, and progress percent
Browse files Browse the repository at this point in the history
  • Loading branch information
victornpb committed May 6, 2022
1 parent cb5d1c6 commit 96f4cca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/deleteMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)} <b>${redact(message.author.username + '#' + message.author.discriminator)} <small>(${redact(new Date(message.timestamp).toLocaleString())})</small>:</b> <i>${redact(message.content).replace(/\n/g, '↵')}</i>`,
Expand Down Expand Up @@ -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 {
Expand Down
29 changes: 18 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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');
Expand All @@ -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
}
Expand All @@ -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';
}

Expand Down

0 comments on commit 96f4cca

Please sign in to comment.