aboutsummaryrefslogtreecommitdiff
path: root/src/utils.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.mjs')
-rw-r--r--src/utils.mjs34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/utils.mjs b/src/utils.mjs
index 97d1255..2fca3f5 100644
--- a/src/utils.mjs
+++ b/src/utils.mjs
@@ -91,31 +91,30 @@ function addTimerBehaviour(t) {
}
export class Manager {
- constructor(description, listData) {
- this.description = description;
- this.listData = listData;
- this.count = listData.length;
+ constructor() {
+ this.data = [];
+ this.count = this.data.length;
}
store() {
- let stringData = JSON.stringify(this.listData);
- localStorage.setItem(this.description, stringData);
+ let stringData = JSON.stringify(this.data);
+ localStorage.setItem(this.data[0].description, stringData);
}
render() {
- let renderedHTML = this.listData
+ let renderedHTML = this.data
.map((i) => {
return i.render();
})
.join("");
- let elementId = this.description + "_list";
+ let elementId = this.data[0].description + "_list";
document.getElementById(elementId).innerHTML = renderedHTML;
this.addBehaviour();
}
addBehaviour() {
- for (let idx = 0; idx < this.listData.length; ++idx) {
- const elementId = this.description + "_" + this.listData[idx].id;
+ for (let idx = 0; idx < this.data.length; ++idx) {
+ const elementId = this.data[0].description + "_" + this.data[idx].id;
const p = document.getElementById(elementId);
p.addEventListener("click", () => {
- this.listData[idx].toggle();
+ this.data[idx].toggle();
this.store();
p.classList.toggle("is-success");
p.classList.toggle("is-danger");
@@ -123,12 +122,12 @@ export class Manager {
}
}
active() {
- return this.listData.filter(function (c) {
+ return this.data.filter(function (c) {
return c.status;
});
}
inactive() {
- return this.listData.filter(function (c) {
+ return this.data.filter(function (c) {
return !c.status;
});
}
@@ -142,6 +141,15 @@ export function shuffle(array) {
return array;
}
+export function randomLevel() {
+ const max_level = 10;
+ return Math.floor(Math.random() * max_level + 1);
+}
+
+export function randomStatus() {
+ return Math.random() < 0.5;
+}
+
export function getNotifier(seconds) {
return new Notyf({
duration: seconds * milliSecond,