forked from kshitij10496/Read-Later
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
91 lines (63 loc) · 2.14 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
/*document.getElementById("submit").addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode == 13) {
document.getElementById("submit").click();
}
});
*/
var count=0;
var storage = chrome.storage.sync;
var sumbit = document.getElementById("submit");
submit.addEventListener("click", function(){
chrome.tabs.getSelected(null, function(tab){
var i =0;
var oldlink = JSON.parse(localStorage.getItem(i));
while(oldlink!=null)
{
console.log(i);
i+=1;
var oldlink = JSON.parse(localStorage.getItem(i));
}
var date = document.getElementById("date").value;
var time = document.getElementById("time").value;
var title = document.getElementById("title").value;
var url = tab.url;
var comments = document.getElementById("comments").value;
var newlink;
var dl = date.split("-");
var tl = time.split(":");
var g = new Date();
var f = new Date();
var currentTimeZoneOffsetInHours = f.getTimezoneOffset()*60000;
g = Date.UTC(+dl[0], dl[1]-1, +dl[2], +tl[0], +tl[1], +0, +0);
//alert(Date(f.getTime()));
var lapse = (g - Date.now() + currentTimeZoneOffsetInHours);
if(lapse>-60000)
{
chrome.alarms.create("notification_delay",{
"when": Date.now() + lapse
})
newlink = {"count":i, "url": url ,"title":title,"time":time,"date":date,"comments":comments,"value":0,"epoch":(Date.now() + lapse)};
localStorage.setItem(i, JSON.stringify(newlink));
alert("Success");
}
else
{
alert("Please Enter Valid Time and Date Input");
}
});
});
window.onload = function(){
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
document.getElementById("title").value = (tabs[0].title);
});
/*var date = new Date();
dateFormat(date, "mm, dd, yyyy, hh:MM ");
document.getElementById("time").value = date.setTime(date.getTime());
document.getElementById("date").value = date.setDate(date.getDate() + 1);
*/
};
/*function myFunction(url,title) {
chrome.bookmarks.create({url: url, title: title});
console.log(url);
}*/