From 507747c5e4b469130914b99ec66df17cfba9f373 Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Fri, 4 Aug 2023 19:57:23 +0800 Subject: [PATCH] NEW FEATURE: clear your own completed tasks - removed "completed tasks" in check - removed useless console log - removed some comments - added one comment in configs.js --- configs.js | 8 +++++++- scripts/index.js | 10 ++++++++++ scripts/taskList.js | 46 ++++++++++++++++++++++++++++++--------------- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/configs.js b/configs.js index e1a2d4b..fa1aafb 100644 --- a/configs.js +++ b/configs.js @@ -74,7 +74,7 @@ const configs = (function () { const taskMarginBottom = "5px"; // px const taskHorizontalPadding = "20px"; // px - const taskVerticalPadding = "10px"; + const taskVerticalPadding = "10px"; // px // Add task commands - please add commands in the exact format const addTaskCommands = [ @@ -136,6 +136,9 @@ const configs = (function () { "!check", ]; + // Clear my done commands - please add commands in the exact format + const clearMyDoneCommands = ["!clearmydone"]; + // Help commands - please add commands in the exact format const helpCommands = [ "!taskh", @@ -193,6 +196,7 @@ const configs = (function () { const notMod = "Permission denied, {user}; Mods only"; const clearedAll = "All tasks have been cleared!"; const clearedDone = "All completed tasks have been cleared!"; + const clearedMyDone = "All your completed tasks have been cleared!"; const specifyUser = "Try specifying a user to delete their tasks {user}"; const help = `{user} Use the following commands to help you out - !task !edit !remove !done. For mods, you can do !adel @user. More commmands here: https://github.com/liyunze-coding/Chat-Task-Tic-Overlay/blob/main/MultiTask.md/`; // to edit check task command, go to @@ -277,6 +281,7 @@ const configs = (function () { finishTaskCommands, helpCommands, checkCommands, + clearMyDoneCommands, adminDeleteCommands, adminClearDoneCommands, adminClearAllCommands, @@ -298,6 +303,7 @@ const configs = (function () { notMod, help, adminDeleteTasks, + clearedMyDone, clearedAll, clearedDone, specifyUser, diff --git a/scripts/index.js b/scripts/index.js index dea6911..92317a5 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -135,6 +135,16 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => { clearAllTasks(); respond(responses.clearedAll, params); } + } else if (commands.clearMyDoneCommands.includes(command)) { + let response = markOwnTaskDone(user); + + if (response === 0) { + // no tasks + respond(responses.noTask, params); + return; + } + + respond(responses.clearedMyDone, params); } else if (commands.helpCommands.includes(command)) { respond(responses.help, params); } else if (commands.additionalCommands[command]) { diff --git a/scripts/taskList.js b/scripts/taskList.js index 5af4865..6911923 100644 --- a/scripts/taskList.js +++ b/scripts/taskList.js @@ -232,6 +232,26 @@ function isInt(value) { ); } +// 0: user has no tasks +// 1: success +function markOwnTaskDone(username) { + const tasks = JSON.parse(localStorage.tasks); + + if (!tasks[username] || tasks[username].todos.length === 0) { + return 0; + } + + let incompleteUserTasks = tasks[username].todos.filter((t) => !t.done); + + // replace user's task with incomplete tasks + tasks[username].todos = incompleteUserTasks; + + localStorage.setItem(`tasks`, JSON.stringify(tasks)); + renderTaskListToDOM(); + + return 1; +} + // 0: user has no tasks // 1: invalid input // task: succcess @@ -354,18 +374,18 @@ function checkTasks(username) { reply = reply.slice(0, -3); // format completed tasks into string: 1. task 1 | 2. task 2 | 3. task 3... - reply += `\n|| completed tasks (${completedTasks.length}) : `; + // reply += `\n|| completed tasks (${completedTasks.length}) : `; - for (let j = 0; j < completedTasks.length; j++) { - taskIndex = - tasks[username].todos.findIndex( - (t) => - t.text.toLowerCase() === - completedTasks[j].text.toLowerCase() - ) + 1; - reply += `${taskIndex}. ${completedTasks[j].text} | `; - } - reply = reply.slice(0, -3); + // for (let j = 0; j < completedTasks.length; j++) { + // taskIndex = + // tasks[username].todos.findIndex( + // (t) => + // t.text.toLowerCase() === + // completedTasks[j].text.toLowerCase() + // ) + 1; + // reply += `${taskIndex}. ${completedTasks[j].text} | `; + // } + // reply = reply.slice(0, -3); return reply; } @@ -425,8 +445,6 @@ function smutOnly(streamer) { function renderTaskListToDOM() { const tasks = JSON.parse(localStorage.tasks); - // console.log(tasks); - const taskContainers = document.querySelectorAll(".task-container"); taskContainers.forEach((taskList) => { taskList.innerHTML = ""; @@ -526,8 +544,6 @@ async function checkToAnimate() { let taskWrapper = document.querySelector(".task-wrapper"); let taskWrapperHeight = taskWrapper.clientHeight; - console.log(taskContainerHeight > taskWrapperHeight); - // scroll task wrapper up and down once if (taskContainerHeight > taskWrapperHeight) { if (!scrolling) {