-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
57 lines (53 loc) · 2.51 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
let startDatePicker = document.getElementById("startDate");
let endDatePicker = document.getElementById("endDate");
let today = new Date();
const dtf = new Intl.DateTimeFormat('en', {year:"numeric",month:"2-digit",day:"2-digit"});
[{ value: mo },,{ value: da },,{ value: ye }] = dtf.formatToParts(today);
endDatePicker.value=`${ye}-${mo}-${da}`;
chrome.storage.sync.get(['year','month','day'], function(result) {
previousDate = new Date(result['year'], result['month'], result['day']);
[{ value: mo },,{ value: da },,{ value: ye }] = dtf.formatToParts(previousDate);
startDatePicker.value=`${ye}-${mo}-${da}`;
});
chrome.storage.sync.get({link: ''}, function(result) {
if( result['link'] ) {
var addDiv = document.getElementById("adress");
var button = document.createElement("input");
button.type = "button";
button.value = "Copy link";
button.addEventListener('click', function() {
navigator.clipboard.writeText(result['link']).then(
function() {
chrome.browserAction.setBadgeText({text:""});
chrome.storage.sync.set({'link': ''});
window.close();
}
);
});
addDiv.appendChild(button);
}
});
let getAdress = document.getElementById("getAdress");
getAdress.addEventListener("click", async () => {
let startDate = startDatePicker.valueAsDate;
let endDate = endDatePicker.valueAsDate;
let newDate = new Date(new Date().setDate(endDate.getDate()+1));
chrome.storage.sync.set({'year': newDate.getFullYear(),
'month': newDate.getMonth(),
'day': newDate.getDate(),
'startYear': startDate.getFullYear(),
'startMonth': startDate.getMonth(),
'startDay': startDate.getDate(),
'endYear': endDate.getFullYear(),
'endMonth': endDate.getMonth(),
'endDay': endDate.getDate()},
function() {
chrome.tabs.create(
{url: "https://runkeeper.com/exportData", active: false},
function (tab) {
chrome.runtime.sendMessage({action: "tabCreated"});
}
);
});
window.close();
});