Skip to content

Commit

Permalink
Added reminders
Browse files Browse the repository at this point in the history
Added reminders, now when we schedule the reminder, it will notify us and if an url was saved, it will auto reload a tab with the saved url, since firefox doesn't let loading urls from javascript, it gives an error
  • Loading branch information
dilanSachi authored May 13, 2018
1 parent e1d48a6 commit 704f293
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
23 changes: 23 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
browser.storage.sync.set({todos:[]});
browser.alarms.onAlarm.addListener(listen);

function listen(alarm){
console.log(alarm);
var prom = browser.storage.sync.get(null);
prom.then((res) => {
console.log(res.todos[parseInt(alarm.name)]);
browser.notifications.create('notify', {
"type": "basic",
"iconUrl": 'icons/clock.jpg',
"title": "Todo4U Notifier",
"message": res.todos[parseInt(alarm.name)]
});
browser.notifications.onClicked.addListener(function(notificationId) {
console.log('Notification ' + notificationId + ' was clicked by the user');
if(res.todos[parseInt(alarm.name)]+3!=''){
browser.tabs.create({
url:res.todos[parseInt(alarm.name)]+3
});
}
});
});
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"icons": {
"48":"icons/clock.jpg"
},
"permissions":["storage","contextMenus","notifications","tabs"],
"permissions":["storage","contextMenus","notifications","tabs","alarms"],
"background":{
"scripts":["background.js"]
},
Expand Down
29 changes: 26 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function viewPrevious(){
document.getElementById('myBtn').addEventListener('click',function(){
if(document.getElementById('todoData').value!=""){
var prom = browser.storage.sync.get(null);
console.log(document.getElementById('checkURL').value);
prom.then((res) => {
var todos=res.todos;
var todo=document.getElementById('todoData').value;
Expand All @@ -34,10 +33,11 @@ document.getElementById('myBtn').addEventListener('click',function(){
var tab=browser.tabs.query({currentWindow:true,active:true});
tab.then((resd,resi)=>{
checkURL=resd[0].url;
console.log("asd"+checkURL);
todos.push(todo);
var len=todos.length-1;
todos.push(date);
todos.push(time);
schedule(date,time,len);
if(document.getElementById('checkURL').checked){
todos.push(checkURL);
}else {
Expand All @@ -51,10 +51,33 @@ document.getElementById('myBtn').addEventListener('click',function(){
});
});
var promi = browser.storage.sync.get(null);
prom.then((res) => {
promi.then((res) => {
console.log(res.todos);
});
}else{
alert('Please Enter Data');
}
});

function schedule(date,time,len){
console.log(date);
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);
console.log(newTimer);
console.log(Date.parse(newTimer));
console.log(Date.now());
const when =Date.parse(newTimer);
console.log(len.toString());
browser.alarms.create(len.toString(), {
when
});
var x=browser.alarms.getAll();
x.then((res)=>{
console.log(res[0]);
});

}

0 comments on commit 704f293

Please sign in to comment.