-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
326 lines (227 loc) · 7.96 KB
/
popup.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
//fetched Quotes
fetch("https://type.fit/api/quotes")
.then(function(response) {
return response.json();
})
.then(function(data) {
// console.log(data);
});
//get the quotes
const settings = {
"async": true,
"crossDomain": true,
"url": "https://type.fit/api/quotes",
"method": "GET"
}
let quote = document.getElementById("M_qote");
let auth = document.getElementById("author");
//selected the new quote every day and displayed on the screen
$.ajax(settings).done(function (response) {
const data = JSON.parse(response);
console.log(data);
var date = new Date();
var day = date.getDate();
// var month = date.getMonth();
var totaldays;
if(day < 16) {
var totaldays = day;
}
else {
totaldays = 30 - day;
}
console.log(totaldays);
const quot = data[totaldays].text;
const authr = data[totaldays].author;
// console.log(quot);
quote.innerHTML = quot;
auth.innerHTML = "~"+authr;
});
//printed new date and day daily.
const date = new Date();
let day = date.getDate();
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const dayname = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
let days = dayname[date.getDay()];
let month = months[date.getMonth()];
let year = date.getFullYear();
let new_date = days+" "+ day + " " + month + " " + year;
console.log(new_date);
let current_date = document.getElementById("date");
current_date.innerHTML = new_date;
//got the input from user
let submit = document.getElementById("sbmit");
let description = document.getElementById('task');
var urgency = document.getElementById("pr");
let time = document.getElementById('tim');
// let descrb = description.value;
// console.log(descrb);
//reloaded the page and displayed the items on the popup page.
window.onload = function () {
let storedvalues = localStorage.getItem('itemsJson');
let items = JSON.parse(storedvalues);
let tablebody = document.getElementById("table");
let string = "";
items.forEach((element, index) => {
string +=
`<tr id="${index}">
<th scope="row">${index+1}</th>
<td>${element[0]}</td>
<td>${element[1]}</td>
<td>${element[2]}</td>
<td><button class="btn btn-success deleting" data-index="${index}">Delete</button></td>
</tr>`
});
tablebody.innerHTML = string;
var deleteButtons = document.querySelectorAll('.deleting');
deleteButtons.forEach(button => {
console.log(deleteButtons)
button.addEventListener('click', function() {
var index = this.dataset.index;
// console.log(index)
userdata = localStorage.getItem('itemsJson');
data = JSON.parse(userdata);
data.splice(index, 1);
console.log(data)
localStorage.setItem('itemsJson',JSON.stringify(data));
function showResult() {
document.location.reload();
};
showResult();
});
})
};
submit.addEventListener("click", function(){
let des = description.value;
let t= time.value;
let u = urgency.value;
if (des == "" || t == "" || u == "") {
alert("Please fill in all fields.");
}
// Save the task in local storage
else {
if (localStorage.getItem("itemsJson") == null) {
let data = [];
data.push([u,des,t]);
localStorage.setItem('itemsJson',JSON.stringify(data));
}
else {
let userdata = localStorage.getItem('itemsJson');
data = JSON.parse(userdata);
// console.log(userdata)
data.push([u,des,t]);
localStorage.setItem('itemsJson',JSON.stringify(data));
};
// update table rows
let tablebody = document.getElementById("table");
let string = "";
data.forEach((element, index) => {
string +=
`<tr id="${index}">
<th scope="row">${index+1}</th>
<td>${element[0]}</td>
<td>${element[1] });}</td>
<td>${element[2]}</td>
<td><button class="btn btn-success deleting" data-index="${index}">Delete</button></td>
</tr>`
});
tablebody.innerHTML = string;
document.location.reload();
chrome.notifications.create('main', {
type: 'basic',
iconUrl: 'logo2.png',
title: 'notification title',
message: 'notification message',
priority: 2
});
// adding event listener for delete buttons
var deleteButtons = document.querySelectorAll('.deleting');
deleteButtons.forEach(button => {
console.log(deleteButtons)
button.addEventListener('click', function() {
var index = this.dataset.index;
// console.log(index)
userdata = localStorage.getItem('itemsJson');
data = JSON.parse(userdata);
data.splice(index, 1);
console.log(data)
document.location.reload();
localStorage.setItem('itemsJson',JSON.stringify(data));
});
});
}
});
// let ele = document.getElementById("Alarm")
// ele.addEventListener("click", () => {
// chrome.runtime.sendMessage({ time: "1" }, function (response) {
// // console.log(response);
// });
// });
// Connect to the background page
// const port = chrome.runtime.connect({ name: "myPort" });
// // Handle button click event
// let ele = document.getElementById("Alarm")
// ele.addEventListener("click", () => {
// // Send a message to the background page
// port.postMessage({time: "1"},function (response) {
// console.log(response);
// });
// });
// content.js
// Establish a connection with the background script
const port = chrome.runtime.connect();
// Define a function that wraps port.postMessage and adds an event listener
function sendMessage(message) {
port.postMessage(message);
// Check if the message is a request to schedule a notification
if (message.scheduleNotification) {
// Send a message to the background script to schedule the notification
port.postMessage({ type: 'scheduleNotification' });
}
}
// Find the button element and add an event listener to it
let ele = document.getElementById("Alarm")
ele.addEventListener('click', () => {
// Use the sendMessage function to send a message to the background script to schedule a notification
sendMessage({ scheduleNotification: true });
});
//start
// function launch() {
// chrome.app.window.create('index.html', {
// id: 'main',
// bounds: { width: 620, height: 500 }
// });
// }
// // chrome.app.runtime.onLaunched.addListener(launch);
// const sound= new Audio(chrome.runtime.getURL("duck.mp3"))
// function showNotification(descrb) {
// sound.play()
// alert("check your tasks");
// if (descrb.length>0) {
// // Now created the notification
// chrome.notifications.create('reminder', {
// type: 'basic',
// iconUrl: 'logo2.png',
// title: 'important notification',
// message: 'You have '+ descrb +' things to do. Wake up, dude!'
// }, () => { });
// }
// }
// // let ntf = document.getElementById("main").value;
// // // let ntf = n0tif.value;
// // userdata = localStorage.getItem('itemsJson');
// // data = JSON.parse(userdata);
// // data.push(ntf);
// // localStorage.setItem('itemsJson', JSON.stringify(data));
// // chrome.app.runtime.addListener(function (){
// // launch();
// // });
// chrome.alarms.onAlarm.addListener(function( alarm ) {
// console.log("Got an alarm!", alarm);
// userdata = localStorage.getItem('itemsJson');
// data = JSON.parse(userdata);
// chrome.storage.local.get("itemsJson", showNotification);
// });
// chrome.notifications.onClicked.addListener(function() {
// launch();
// });
// // localStorage.setItem('itemsJson', JSON.stringify(data));