-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
216 lines (182 loc) · 7.68 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//----------------------------------TODO APP-------------------------------------------
//gettting all required elements
const inputBox = document.querySelector(".inputField input");
const addBtn = document.querySelector(".inputField button");
const todoList = document.querySelector(".todoList");
const deleteAllBtn = document.querySelector(".todo-footer button");
inputBox.onkeyup = ()=>{
let userData = inputBox.value; //getting user entered value
if(userData.trim() != 0){ //if user value is not only space
addBtn.classList.add("active"); //active the add button
}else{
addBtn.classList.remove("active"); //unactive the add button
}
}
showTasks(); //calls the function showTasks
//if user click on the add button
addBtn.onclick = ()=>{
let userData = inputBox.value;
let getLocalStorage = localStorage.getItem("New Todo"); //getting localstorage
if(getLocalStorage == null){ //if localstorage is null
listArr = []; //creating blank array
}else{
listArr = JSON.parse(getLocalStorage); //transforming json strting into a json object
}
listArr.push(userData); //pushing or adding user data
localStorage.setItem("New Todo", JSON.stringify(listArr)); //transform js object into a json string
showTasks(); //calls showTasks function
addBtn.classList.remove("active"); //unactive the add button
}
//funciton to add task list inside ul
function showTasks(){
let getLocalStorage = localStorage.getItem("New Todo"); //getting localstorage
if(getLocalStorage == null){ //if localstorage is null
listArr = []; //creating blank array
}else{
listArr = JSON.parse(getLocalStorage); //transforming json strting into a json object
}
const pendingNumb = document.querySelector(".pendingNumb");
pendingNumb.textContent = listArr.length; //passing the length value in pendingNub
if(listArr.length > 0){ //if arrayy length is greater than 0
deleteAllBtn.classList.add("active"); //active the clearall button
}else{
deleteAllBtn.classList.remove("active"); //unactive the clear all button
}
let newLiTag = '';
listArr.forEach((element, index) => {
newLiTag += `<li> ${element} <span onclick="deleteTask(${index})"; ><i class="fas fa-trash"></i></span></li>` ;
});
todoList.innerHTML = newLiTag; //adding new li tag inside ul tag
inputBox.value = ""; //once task added leave the input field blank
}
//delete task function
function deleteTask(index){
let getLocalStorage = localStorage.getItem("New Todo"); //getting localstorage
listArr = JSON.parse(getLocalStorage); //transforming json strting into a json object
listArr.splice(index, 1); //delete or remove te particular indexed li
// after remove the li again update the localstorage
localStorage.setItem("New Todo", JSON.stringify(listArr)); //transform js object into a json string
showTasks();
}
//delete all tasks function
deleteAllBtn.onclick = ()=>{
listArr = []; //empty the array
// after deletingthe all tasks again update the localstorage
localStorage.setItem("New Todo", JSON.stringify(listArr)); //transform js object into a json string
showTasks();
}
//-----------------------TODO APP END----------------------------------------------------
//---------------------POMODORO APP START --------------------------------------------
//timer----------
const el = document.querySelector(".clock");
const bell = document.querySelector("audio");
const mindiv = document.querySelector(".mins");
const secdiv = document.querySelector(".secs");
const startBtn = document.querySelector(".start");
localStorage.setItem("btn", "focus");
let initial, totalsecs, perc, paused, mins, seconds;
startBtn.addEventListener("click", () => {
let btn = localStorage.getItem("btn");
if(btn == "focus"){
mins = +localStorage.getItem("focusTime");
}else{
mins = +localStorage.getItem("breakTime");
}
seconds = mins * 60;
totalsecs = mins * 60;
setTimeout(decremenT(), 60);
startBtn.style.transform = "scale(0)";
paused = false;
});
function decremenT(){
mindiv.textContent = Math.floor(seconds / 60);
secdiv.textContent = seconds % 60 > 9 ? seconds % 60 : `0${seconds % 60}`;
if(circle.classList.contains("danger")){
circle.classList.remove("danger");
}
if(seconds > 0){
perc = Math.ceil(((totalsecs - seconds) / totalsecs) * 100);
setProgress(perc);
seconds--;
initial = window.setTimeout("decremenT()", 1000);
if(seconds < 10){
circle.classList.add("danger");
}
}else{
mins = 0;
seconds = 0;
bell.play();
let btn = localStorage.getItem("btn");
if(btn == "focus"){
startBtn.textContent = "start break";
startBtn.classList.add("break");
localStorage.setItem("btn", "break");
}else{
startBtn.classList.remove("break");
startBtn.textContent = "start focus";
localStorage.setItem("btn", "break");
}
startBtn.style.transform = "scale(1)";
}
}
//progress-------------------------------------
const circle = document.querySelector(".progress-ring__circle");
const radius = circle.r.baseVal.value;
const circumference = radius * 2 * Math.PI;
circle.style.strokeDasharray = circumference;
circle.style.strokeDashoffset = circumference;
function setProgress(percent){
const offset = circumference - (percent / 100) * circumference;
circle.style.strokeDashoffset = offset;
}
//settings----------------------------------
const focusTimeInput = document.querySelector("#focusTime");
const breakTimeInput = document.querySelector("#breakTime");
const pauseBtn = document.querySelector(".pause");
const focusPH = document.querySelector(".studyInput");
const breakPH = document.querySelector(".breakInput");
document.querySelector("form").addEventListener("submit", (e) =>{
e.preventDefault();
localStorage.setItem("focusTime", focusTimeInput.value);
localStorage.setItem("breakTime", breakTimeInput.value);
focusPH.value = localStorage.focusTime;
breakPH.value = localStorage.breakTime;
});
document.querySelector(".reset").addEventListener("click", () =>{
startBtn.style.transform = "scale(1)";
clearTimeout(initial);
setProgress(0);
mindiv.textContent = 0;
secdiv.textContent = 0;
});
pauseBtn.addEventListener("click", () => {
if(paused == undefined){
return;
}
if(paused){
paused = false;
initial = setTimeout("decremenT()", 60);
pauseBtn.textContent = "pause";
pauseBtn.classList.remove("resume");
}else{
clearTimeout(initial);
pauseBtn.textContent = "resume";
pauseBtn.classList.add("resume");
paused = true;
}
});
$(document).ready(function(){
var status = 0;
$("#hiddenForm").hide();
$("#buttonHide").click(function(e){
if(status == 0){
$("#hiddenForm").show(500);
status = 1;
}else{
$("#hiddenForm").hide(500);
status = 0;
}
});
focusPH.value = localStorage.focusTime;
breakPH.value = localStorage.breakTime;
})