-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackmark.js
More file actions
81 lines (75 loc) · 2.42 KB
/
backmark.js
File metadata and controls
81 lines (75 loc) · 2.42 KB
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
// Generated by CoffeeScript 1.8.0
chrome.runtime.onInstalled.addListener(function(details) {
if (details.reason === 'install') {
console.log("just installed, prompting user");
return chrome.tabs.createAsync({
url: 'popup.html?reason=firstrun'
});
}
});
chrome.bookmarks.onCreated.addListener(function(id, bookmark) {
console.log("bookmark created, running full backup");
return runMissingBackup();
});
chrome.bookmarks.onRemoved.addListener(function(id, info) {
console.log("bookmark removed, deleting entry");
if (info.hasOwnProperty('node') && info.node.hasOwnProperty('url')) {
return removeEntry(info.node.url);
} else {
return console.log('not removing entry, newer Chrome required');
}
});
chrome.bookmarks.onChanged.addListener(function(id, info) {
console.log("bookmark changed, running full backup");
return runMissingBackup();
});
chrome.bookmarks.onMoved.addListener(function(id, info) {
console.log("bookmark moved, running full backup");
return runMissingBackup();
});
chrome.runtime.onMessage.addListener(function(req, sender, sendResponse) {
var urls;
switch (req.msg) {
case 'download':
return mkTabLoaded(req.tabId).then(function(tab) {
return chrome.tabs.sendMessage(tab.id, req.acceptDangerDownload);
});
case 'partialBackup':
urls = req.urls;
console.log('user requested backup of:', urls);
return getBookmarks().then(function(bookmarks) {
return _.filter(bookmarks, function(b) {
return _.includes(urls, b.url);
});
}).then(function(bookmarks) {
return runBackup(bookmarks, true);
}).then(function() {
console.log('responding');
return sendResponse({
msg: 'backupComplete'
});
});
case 'missingBackup':
console.log('user requested missing backup:', urls);
return runMissingBackup().then(function() {
console.log('responding');
return sendResponse({
msg: 'backupComplete'
});
});
case 'partialDownload':
return chrome.tabs.createAsync({
url: 'acceptDanger.html',
active: true,
selected: true
}).then(function(tab) {
return mkTabLoaded(tab.id);
}).then(function(tab) {
return chrome.tabs.sendMessage(tab.id, {
msg: 'acceptDanger-partialDownload',
urls: req.urls
});
});
}
});
//# sourceMappingURL=backmark.js.map