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
This commit is contained in:
parent
dae6c59363
commit
507747c5e4
3 changed files with 48 additions and 16 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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]) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue