-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
53 lines (49 loc) · 1.65 KB
/
background.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
chrome.runtime.onInstalled.addListener(function() {
let yesterday = new Date(new Date().setDate(new Date().getDate()-1));
chrome.storage.sync.set({'year': yesterday.getFullYear(), 'month': yesterday.getMonth(), 'day': yesterday.getDate()}, function() {
});
});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.action == "tabCreated" ) {
setTimeout(checkLoad, 2000);
}
else if( request.action == "submit" ) {
setTimeout(checkLink, 1000, sender);
}
}
);
function checkLoad(){
chrome.tabs.query(
{status: "complete", url: "https://runkeeper.com/exportData" },
function (tabs) {
var find = false;
for(var i = 0; i < tabs.length && !find; i++){
chrome.tabs.executeScript(tabs[i].id, {file: 'submitform.js'} );
find = true;
}
if( !find ) {
setTimeout(checkLoad, 1000)
}
}
)
}
function checkLink(sender) {
chrome.tabs.reload(sender.tab.id, function() {
chrome.tabs.executeScript(
sender.tab.id, {file:"findLink.js"},
function(result) {
if(result[0]) {
chrome.storage.sync.set({'link': result[0]}, function() {
chrome.browserAction.setBadgeText({text:"tot"}, function() {
});
});
chrome.tabs.remove(sender.tab.id);
}
else {
setTimeout(checkLink, 2000, sender);
}
}
)
});
};