-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
100 lines (91 loc) · 3.12 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
document.getElementById('myBtnII').addEventListener('click',function(){
viewPrevious();
});
function viewPrevious(){
var prom = browser.storage.sync.get(null);
prom.then((res) => {
var ul = document.createElement('ul');
ul.classList.add('list-group', 'list-group-flush');
var i;
for (i = 0; i < res.todos.length; i+=4) {
var li = document.createElement('li');
li.classList.add('list-group-item');
li.textContent = res.todos[i]+' '+res.todos[i+1]+' '+res.todos[i+2];
ul.appendChild(li);
if(res.todos[i+3]!=''){
var li = document.createElement('li');
li.classList.add('list-group-item');
li.textContent = "Saved URL : "+res.todos[i+3];
ul.appendChild(li);
}
var button = document.createElement('button');
button.classList.add('btn', 'btn-primary');
button.addEventListener('click', myFunc);
button.id = i;
button.innerText="Delete";
ul.appendChild(button);
}
document.getElementById("oldTodos").innerHTML = '';
document.getElementById("oldTodos").appendChild(ul);
});
}
function myFunc(){
var prom=browser.storage.sync.get(null);
prom.then((res)=>{
var todos=res.todos;
todos.splice(parseInt(this.id),4);
var succes=browser.storage.sync.set({todos:todos});
succes.then((response)=>{
viewPrevious();
});
});
}
document.getElementById('myBtn').addEventListener('click',function(){
if(document.getElementById('todoData').value!="" && document.getElementById('date').value!='' && document.getElementById('time').value==''){
alert("Enter time");
}else if(document.getElementById('todoData').value!='' && document.getElementById('date').value=='' && document.getElementById('time').value!=''){
alert("Enter date");
}else if(document.getElementById('todoData').value!=""){
var prom = browser.storage.sync.get(null);
prom.then((res) => {
var todos=res.todos;
var todo=document.getElementById('todoData').value;
var date=document.getElementById('date').value;
var time=document.getElementById('time').value;
var checkURL='';
var tab=browser.tabs.query({currentWindow:true,active:true});
tab.then((resd,resi)=>{
checkURL=resd[0].url;
todos.push(todo);
todos.push(date);
todos.push(time);
if(date!='' && time!=''){
schedule(date,time,todo);
}
if(document.getElementById('checkURL').checked){
todos.push(checkURL);
}else {
todos.push('');
}
var succes=browser.storage.sync.set({todos:todos});
succes.then((response)=>{
viewPrevious();
});
});
});
}else{
alert('Please Enter Data');
}
});
function schedule(date,time,todo){
var myYear=parseInt(date.slice(0,4));
var myMonth=parseInt(date.slice(5,7))-1;
var myDay=parseInt(date.slice(8,10));
var myHour=parseInt(time.slice(0,2));
var myMin=parseInt(time.slice(3,5));
var newTimer=new Date(myYear,myMonth,myDay,myHour,myMin);
const when =Date.parse(newTimer);
browser.alarms.create(todo, {
when
});
}