First commit, might not be stable

This commit is contained in:
liyunze 2023-11-12 13:24:00 +08:00
parent 0627afee87
commit efcc8000f8
4 changed files with 68 additions and 203 deletions

View file

@ -2,8 +2,11 @@ const configs = (function () {
"use strict"; "use strict";
// settings // settings
const enableLimit = true; // true or false const enableLimit = false; // true or false
const limit = 5; // integer const limit = 10; // integer
const modifyLocalStorage = true; // true or false
const showOnlyStreamerTasks = false; // true or false
// animation // animation
const scrollSpeed = 40; // milliseconds const scrollSpeed = 40; // milliseconds
@ -12,11 +15,11 @@ const configs = (function () {
// STYLES // STYLES
// task list // task list
const taskListBackgroundColor = "#000000"; // hex only const taskListBackgroundColor = "#000000"; // hex only
const taskListBackgroundOpacity = 0; // 0.0 - 1.0 const taskListBackgroundOpacity = 1; // 0.0 - 1.0
const taskListBorderWidth = "0px"; // px const taskListBorderWidth = "0px"; // px
const taskListBorderColor = "#ffffff"; // hex or name const taskListBorderColor = "#ffffff"; // hex or name
const taskListBorderRadius = "5px"; // px const taskListBorderRadius = "0px"; // px
const taskListHorizontalPadding = "0px"; // px const taskListHorizontalPadding = "0px"; // px
const taskListVerticalPadding = "0px"; // px const taskListVerticalPadding = "0px"; // px
@ -25,12 +28,12 @@ const configs = (function () {
const headerHorizontalPadding = "10px"; // px const headerHorizontalPadding = "10px"; // px
const headerVerticalPadding = "10px"; // px const headerVerticalPadding = "10px"; // px
const headerBackgroundColor = "#000000"; // hex only const headerBackgroundColor = "#000"; // hex only
const headerBackgroundOpacity = 0.8; // 0.0 - 1.0 const headerBackgroundOpacity = 1; // 0.0 - 1.0
const headerBorderWidth = "2px"; // px const headerBorderWidth = "2px"; // px
const headerBorderColor = "#ffffff"; // hex or name const headerBorderColor = "#ffffff"; // hex or name
const headerBorderRadius = "5px"; // px const headerBorderRadius = "3px"; // px
const headerFontFamily = "Fredoka"; // font name const headerFontFamily = "Fredoka"; // font name
const headerGoogleFont = true; // true: use google font, false: use system font const headerGoogleFont = true; // true: use google font, false: use system font
@ -38,10 +41,10 @@ const configs = (function () {
const headerFontSize = "25px"; // px const headerFontSize = "25px"; // px
const headerFontWeight = "bold"; // normal or bold or number const headerFontWeight = "bold"; // normal or bold or number
const headerFontColor = "#ffffff"; // hex or name const headerFontColor = "#fff"; // hex or name
// body // body
const bodyBackgroundColor = "#000000"; // hex only const bodyBackgroundColor = "#fff"; // hex only
const bodyBackgroundOpacity = 0; // 0.0 - 1.0 const bodyBackgroundOpacity = 0; // 0.0 - 1.0
const bodyBorderWidth = "0px"; // px const bodyBorderWidth = "0px"; // px
@ -51,24 +54,24 @@ const configs = (function () {
// task // task
const lineHeight = 1.5; // number const lineHeight = 1.5; // number
const usernameFontWeight = "bold"; // normal or bold or number const usernameFontWeight = "bold"; // normal or bold or number
const usernameColor = "#ffc0cb"; // hex or name or "" for twitch user color const usernameColor = "pink"; // hex or name or "" for twitch user color
const taskWidth = "100%"; const taskWidth = "100%";
const taskBackgroundColor = "#000000"; // hex only const taskBackgroundColor = "#fff"; // hex only
const taskBackgroundOpacity = 0.7; // 0.0 - 1.0 const taskBackgroundOpacity = 0; // 0.0 - 1.0
const taskFontFamily = "Poppins"; // font name const taskFontFamily = "Poppins"; // font name
const taskGoogleFont = true; // true: use google font, false: use system font const taskGoogleFont = true; // true: use google font, false: use system font
const taskFontSize = "20px"; // px const taskFontSize = "20px"; // px
const taskFontColor = "#ffffff"; // hex or name const taskFontColor = "#fff"; // hex or name
const taskBorderColor = "#000000"; // hex or name const taskBorderColor = "#fff"; // hex or name
const taskBorderWidth = "0px"; // px const taskBorderWidth = "0px"; // px
const taskBorderRadius = "5px"; // px const taskBorderRadius = "10px"; // px
const taskMarginBottom = "5px"; // px const taskMarginBottom = "10px"; // px
const taskHorizontalPadding = "20px"; // px const taskHorizontalPadding = "20px"; // px
const taskVerticalPadding = "10px"; // px const taskVerticalPadding = "10px"; // px
@ -81,6 +84,7 @@ const configs = (function () {
"!task", "!task",
"!add", "!add",
"!todo", "!todo",
"!a",
]; ];
// Edit task commands - please add commands in the exact format // Edit task commands - please add commands in the exact format
@ -90,11 +94,11 @@ const configs = (function () {
"!etask", "!etask",
"!edittask", "!edittask",
"!edit", "!edit",
"!e",
]; ];
// Delete task commands - please add commands in the exact format // Delete task commands - please add commands in the exact format
const deleteTaskCommands = [ const deleteTaskCommands = [
"!taskd",
"!taskdel", "!taskdel",
"!taskdelete", "!taskdelete",
"!deltask", "!deltask",
@ -105,6 +109,7 @@ const configs = (function () {
"!removetask", "!removetask",
"!remove", "!remove",
"!delete", "!delete",
"!r",
]; ];
// Finish task commands - please add commands in the exact format // Finish task commands - please add commands in the exact format
@ -120,6 +125,7 @@ const configs = (function () {
"!finish", "!finish",
"!done", "!done",
"!finished", "!finished",
"!f",
]; ];
// Unfinish task commands - please add commands in the exact format // Unfinish task commands - please add commands in the exact format
@ -134,6 +140,7 @@ const configs = (function () {
"!undone", "!undone",
"!unfinish", "!unfinish",
"!unfinished", "!unfinished",
"!u",
]; ];
// Check task commands - please add commands in the exact format // Check task commands - please add commands in the exact format
@ -250,6 +257,8 @@ const configs = (function () {
limit, limit,
headerGoogleFont, headerGoogleFont,
taskGoogleFont, taskGoogleFont,
modifyLocalStorage,
showOnlyStreamerTasks,
}; };
const styles = { const styles = {
@ -276,6 +285,7 @@ const configs = (function () {
bodyBorderWidth, bodyBorderWidth,
bodyBorderColor, bodyBorderColor,
bodyBorderRadius, bodyBorderRadius,
taskWidth, taskWidth,
lineHeight, lineHeight,
usernameFontWeight, usernameFontWeight,

View file

@ -3,17 +3,6 @@ const responses = configs.responses;
let params = {}; let params = {};
function respond(template, params) {
ComfyJS.Say(
template
.replace("{user}", `@${params.user}`)
.replace("{message}", params.message)
.replace("{mentioned}", `@${params.mentioned}`)
.replace("{task}", params.task)
.replace("{originalTask}", params.originalTask)
);
}
function isMod(flags) { function isMod(flags) {
return flags.broadcaster || flags.mod; return flags.broadcaster || flags.mod;
} }
@ -21,205 +10,54 @@ function isMod(flags) {
ComfyJS.onCommand = (user, command, message, flags, extra) => { ComfyJS.onCommand = (user, command, message, flags, extra) => {
command = `!${command.toLowerCase()}`; command = `!${command.toLowerCase()}`;
params = {
user: user,
message: message,
mentioned: "",
task: "",
originalTask: "",
};
if (commands.addTaskCommands.includes(command)) { if (commands.addTaskCommands.includes(command)) {
let addStatus = addTask(user, extra.userColor, message); addTask(user, extra.userColor, message);
if (addStatus === 0) {
// limit has reached
respond(responses.noTaskAdded, params);
} else if (addStatus === 1) {
// duplicate task
respond(responses.duplicateTask, params);
} else if (addStatus === 2) {
// task has no content
respond(responses.noTaskContent, params);
} else {
let addResponse = responses.taskAdded;
params.task = addStatus.task;
if (addStatus.tasksFailedToAdd !== "") {
addResponse += ` | Failed to add task(s): "${addStatus.tasksFailedToAdd}"`;
}
// task added
respond(addResponse, params);
}
} else if (commands.editTaskCommands.includes(command)) { } else if (commands.editTaskCommands.includes(command)) {
let editStatus = editTask(user, message); return editTask(user, message);
if (editStatus === 0) {
// no task
respond(responses.noTask, params);
} else if (editStatus === 1) {
// invalid input
respond(responses.noTaskEdit, params);
} else {
// task edited
params.task = editStatus[1];
params.originalTask = editStatus[0];
respond(responses.taskEdited, params);
}
} else if (commands.deleteTaskCommands.includes(command)) { } else if (commands.deleteTaskCommands.includes(command)) {
let removeStatus = removeTask(user, message); removeTask(user, message);
if (removeStatus === 0) {
// no task
respond(responses.noTask, params);
} else if (removeStatus === 1) {
// invalid input
respond(responses.specifyTaskIndex, params);
} else {
// task deleted
let deletedResponse = responses.taskDeleted;
params.task = removeStatus.removedTasks;
if (removeStatus.failedTasks !== "") {
deletedResponse += ` | Failed to delete task(s): "${removeStatus.failedTasks}"`;
}
respond(deletedResponse, params);
}
} else if (commands.finishTaskCommands.includes(command)) { } else if (commands.finishTaskCommands.includes(command)) {
if (message === "all") { if (message === "all") {
let finishAllStatus = markAllTasksAsDone(user); return markAllTasksAsDone(user);
if (finishAllStatus === 0) {
// user has no tasks
respond(responses.noTask, params);
} else {
// all tasks finished
let finishedResponse = responses.allTasksFinished;
respond(finishedResponse, params);
} }
return; return markTaskDone(user, message);
}
let finishStatus = markTaskDone(user, message);
if (finishStatus === 0) {
// user has no tasks
respond(responses.noTask, params);
} else if (finishStatus === 1) {
// invalid input
respond(responses.specifyTaskIndex, params);
} else {
// task finished
let finishedResponse = responses.taskFinished;
params.task = finishStatus.markedTasks;
if (finishStatus.failedTasks !== "") {
finishedResponse += ` | Failed to finish task(s): "${finishStatus.failedTasks}"`;
}
respond(finishedResponse, params);
}
} else if (commands.unfinishTaskCommands.includes(command)) { } else if (commands.unfinishTaskCommands.includes(command)) {
let unfinishStatus = markTaskUndone(user, message); markTaskUndone(user, message);
if (unfinishStatus === 0) {
// user has no tasks
respond(responses.noTask, params);
} else if (unfinishStatus === 1) {
// invalid input
respond(responses.specifyTaskIndex, params);
} else {
// task unfinished
let unfinishedResponse = responses.taskUnfinished;
params.task = unfinishStatus.markedTasks;
if (unfinishStatus.failedTasks !== "") {
unfinishedResponse += ` | Failed to unfinish task(s): "${unfinishStatus.failedTasks}"`;
}
respond(unfinishedResponse, params);
}
} else if (commands.checkCommands.includes(command)) {
if (message === "") {
let response = checkTasks(user);
if (response === 0) {
return respond(responses.noTask, params);
}
return ComfyJS.Say(response);
} else {
let mentioned = message.replace("@", "");
let response = checkTasks(mentioned);
if (response === 0) {
// no tasks
return respond(responses.noTaskA, params);
}
return ComfyJS.Say(response);
}
} else if (commands.adminDeleteCommands.includes(command)) { } else if (commands.adminDeleteCommands.includes(command)) {
if (!isMod(flags)) { if (!isMod(flags)) {
respond(responses.notMod, params);
return; return;
} }
let mentioned = message.replace("@", ""); let mentioned = message.replace("@", "");
if (mentioned === "") { if (mentioned === "") {
respond(responses.specifyUser, params);
return; return;
} }
clearUserTasks(mentioned); clearUserTasks(mentioned);
params.mentioned = mentioned;
respond(responses.adminDeleteTasks, params);
return mentioned;
} else if (commands.adminClearDoneCommands.includes(command)) { } else if (commands.adminClearDoneCommands.includes(command)) {
if (!isMod(flags)) { if (!isMod(flags)) {
respond(responses.notMod, params);
return; return;
} else { } else {
clearAllDoneTasks(); clearAllDoneTasks();
respond(responses.clearedDone, params);
} }
} else if (commands.adminClearAllCommands.includes(command)) { } else if (commands.adminClearAllCommands.includes(command)) {
if (!isMod(flags)) { if (!isMod(flags)) {
respond(responses.notMod, params);
return; return;
} else { } else {
clearAllTasks(); clearAllTasks();
respond(responses.clearedAll, params);
} }
} else if (commands.clearMyDoneCommands.includes(command)) { } else if (commands.clearMyDoneCommands.includes(command)) {
let response = clearOwnDoneTasks(user); clearOwnDoneTasks(user);
if (response === 0) {
// no tasks
respond(responses.noTask, params);
return;
}
respond(responses.clearedMyDone, params);
} else if (commands.adminClearNotStreamerCommands.includes(command)) { } else if (commands.adminClearNotStreamerCommands.includes(command)) {
clearAllExceptStreamer(auth.channel); if (!isMod(flags)) {
respond(responses.clearTasksExceptBroadcaster, params);
} else if (commands.helpCommands.includes(command)) {
respond(responses.help, params);
} else if (commands.listCommands.includes(command)) {
let response = listTasks(user);
if (response === 0) {
respond(responses.noTask, params);
return; return;
}
ComfyJS.Say(response);
} else if (commands.additionalCommands[command]) {
respond(commands.additionalCommands[command], params);
} else { } else {
// command not found clearAllExceptStreamer(auth.channel);
}
} }
}; };
ComfyJS.Init(auth.username, `oauth:${auth.oauth}`, [auth.channel]); if (configs.settings.modifyLocalStorage) {
ComfyJS.Init(auth.username, `oauth:${auth.oauth}`, [auth.channel]);
}

View file

@ -262,7 +262,9 @@ function removeTask(username, task) {
if (isInt(t)) { if (isInt(t)) {
index = parseInt(t) - 1; // ACTUAL INDEX index = parseInt(t) - 1; // ACTUAL INDEX
} else if (incompleteTasks.length === 1) { } else if (incompleteTasks.length === 1) {
index = tasks[username].todos.findIndex((t) => !t.done); index = tasks[username].todos.findIndex(
(t) => !t.done
);
tasksRemoved.push(tasks[username].todos[index].text); tasksRemoved.push(tasks[username].todos[index].text);
removedTaskIndex.push(index); removedTaskIndex.push(index);
} else { } else {
@ -401,8 +403,12 @@ function markTaskDone(username, task) {
if (isInt(t)) { if (isInt(t)) {
index = parseInt(t) - 1; // ACTUAL INDEX index = parseInt(t) - 1; // ACTUAL INDEX
} else if (incompleteTasks.length === 1) { } else if (incompleteTasks.length === 1) {
index = tasks[username].todos.findIndex((t) => !t.done); index = tasks[username].todos.findIndex(
tasksMarkedComplete.push(tasks[username].todos[index].text); (t) => !t.done
);
tasksMarkedComplete.push(
tasks[username].todos[index].text
);
} else { } else {
tasksFailedToComplete.push(t); tasksFailedToComplete.push(t);
continue; continue;
@ -412,7 +418,9 @@ function markTaskDone(username, task) {
tasksFailedToComplete.push(t); tasksFailedToComplete.push(t);
continue; continue;
} else { } else {
tasksMarkedComplete.push(tasks[username].todos[index].text); tasksMarkedComplete.push(
tasks[username].todos[index].text
);
} }
} else { } else {
tasksMarkedComplete.push(tasks[username].todos[index].text); tasksMarkedComplete.push(tasks[username].todos[index].text);
@ -526,7 +534,9 @@ function markTaskUndone(username, task) {
tasksFailedToMarkUndone.push(t); tasksFailedToMarkUndone.push(t);
continue; continue;
} else { } else {
tasksMarkedUndone.push(tasks[username].todos[index].text); tasksMarkedUndone.push(
tasks[username].todos[index].text
);
} }
} else { } else {
tasksMarkedUndone.push(tasks[username].todos[index].text); tasksMarkedUndone.push(tasks[username].todos[index].text);
@ -775,7 +785,7 @@ function clearAllExceptStreamer(streamer) {
} }
function renderTaskListToDOM() { function renderTaskListToDOM() {
const tasks = JSON.parse(localStorage.tasks); let tasks = JSON.parse(localStorage.tasks);
const taskContainers = document.querySelectorAll(".task-container"); const taskContainers = document.querySelectorAll(".task-container");
taskContainers.forEach((taskList) => { taskContainers.forEach((taskList) => {
@ -783,6 +793,17 @@ function renderTaskListToDOM() {
let totalTaskCount = 0; let totalTaskCount = 0;
let completedTasksCount = 0; let completedTasksCount = 0;
if (settings.showOnlyStreamerTasks) {
// filter out tasks that are not from the streamer
tasks = Object.keys(tasks).reduce((obj, key) => {
if (key.toLowerCase() === auth.channel.toLowerCase()) {
obj[key] = tasks[key];
}
return obj;
}, {});
}
for (const user in tasks) { for (const user in tasks) {
const userTasks = tasks[user]; const userTasks = tasks[user];
if (userTasks.todos.length === 0) { if (userTasks.todos.length === 0) {
@ -954,7 +975,7 @@ function cancelAnimation() {
secondaryAnimation.cancel(); secondaryAnimation.cancel();
} }
scrolling = false; scrolling = false;
console.log("animation cancelled"); // console.log("animation cancelled");
} }
(function () { (function () {

View file

@ -43,10 +43,6 @@
box-sizing: border-box; box-sizing: border-box;
} }
body {
background-color: gray;
}
#main-container { #main-container {
width: 100%; width: 100%;
height: 100vh; height: 100vh;