From 8b7d1f8660bbee1c1b0214a19ce9b9f4c9f0aa16 Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Fri, 22 Dec 2023 22:45:09 +0800 Subject: [PATCH] add points when complete task --- scripts/taskList.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/taskList.js b/scripts/taskList.js index 09c5b67..f3fa255 100644 --- a/scripts/taskList.js +++ b/scripts/taskList.js @@ -269,6 +269,15 @@ function addDoneCount(username, value) { counts.users[username.toLowerCase()].completeCount += value; counts.totalCompleteCount += value; + // check if user has points + if (!counts.users[username.toLowerCase()].points) { + counts.users[username.toLowerCase()].points = 0; + } + + // add to points + counts.users[username.toLowerCase()].points += + value * settings.pointsPerTask; + localStorage.setItem(`counts`, JSON.stringify(counts)); } @@ -911,7 +920,7 @@ function removeTask(username, task) { let tasksFailedToRemove = []; // check if there's a comma in the task (multiple tasks) - if (task.includes(",") || task.includes(";")) { + if (taskSeparator.some((separator) => task.includes(separator))) { let tasksToRemove = []; let char = taskSeparator.find((element) => task.includes(element)); @@ -1118,7 +1127,7 @@ function markTaskDone(username, task) { let tasksFailedToComplete = []; // check if there's a comma in the task (multiple tasks) - if (task.includes(",") || task.includes(";")) { + if (taskSeparator.some((separator) => task.includes(separator))) { // let tasksToMarkDone = task.split(",").map((t) => t.trim()); let tasksToMarkDone = []; @@ -1343,7 +1352,7 @@ function markTaskUndone(username, task) { let tasksFailedToMarkUndone = []; // check if there's a comma in the task (multiple tasks) - if (task.includes(",") || task.includes(";")) { + if (taskSeparator.some((separator) => task.includes(separator))) { let tasksToMarkUndone; let char = taskSeparator.find((element) => task.includes(element));