-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
89 lines (83 loc) · 2.84 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
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
82
83
84
85
86
87
88
89
chrome.contextMenus.create({
title: "Save Instagram Image",
contexts:["page", "selection", "link"],
documentUrlPatterns: ["https://www.instagram.com/","https://www.instagram.com/*"],
onclick: function(info, tab){
console.log("Requesting Instagram download");
chrome.tabs.sendMessage(tab.id, {event:'saveInstagramImage'});
}
});
chrome.contextMenus.create({
title: "Save Flickr Image",
contexts:["page", "selection", "link"],
documentUrlPatterns: ["https://www.flickr.com/photos/*","https://www.flickr.com/groups/*"],
onclick: function(info, tab){
console.log("Requesting Flickr download");
chrome.tabs.sendMessage(tab.id, {event:'saveFlickrImage'});
}
});
var labsMenuItem = chrome.contextMenus.create({
"documentUrlPatterns": [ window.location.protocol + "//" + window.location.hostname + "/*" ],
"title":"Advanced/Labs Features",
"contexts":["browser_action"],
});
chrome.contextMenus.create({
title: "Enable SaveStorm (single-click download)",
contexts: ["browser_action"],
documentUrlPatterns: [ window.location.protocol + "//" + window.location.hostname + "/*" ],
type: "checkbox",
checked: false,
parentId:labsMenuItem,
onclick: function(info, tab) {
saveStorm = info.checked;
chrome.tabs.query({}, function(tabs) {
tabs.forEach(tab => {
if(info.checked)
chrome.tabs.sendMessage(tab.id, {event: "saveStorm"}, function(response) {});
else
chrome.tabs.sendMessage(tab.id, {event: "saveStormStop"}, function(response) {});
})
});
}
});
chrome.contextMenus.create({
title: "DL All Flickr Single-Image Tabs in Window",
contexts: ["browser_action"],
documentUrlPatterns: [ window.location.protocol + "//" + window.location.hostname + "/*" ],
parentId:labsMenuItem,
onclick: function(info, tab) {
chrome.tabs.query({"lastFocusedWindow": true}, function(tabs) {
triggerSaveFlickrBatch(tabs, 0);
//tabs.forEach(tab => {
// chrome.tabs.sendMessage(tab.id, {event: "saveFlickrImage"}, function(response) {});
//});
});
}
});
function triggerSaveFlickrBatch(tabs, startIndex) {
var endIndex = startIndex + 3;
if(tabs.length < endIndex)
endIndex = tabs.length;
for (i = startIndex; i < endIndex; i++) {
//console.log("Sending DL request to " + tabs[i].id)
chrome.tabs.sendMessage(tabs[i].id, {event: "saveFlickrImage"}, function(response) {});
}
if(endIndex < tabs.length) {
setTimeout(triggerSaveFlickrBatch, 2000, tabs, endIndex);
}
}
var saveStorm = false;
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
//console.log("notifying " + saveStorm)
if(request.getSaveStorm) {
sendResponse({saveStorm: saveStorm});
}
});
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {event: "saveIgStoryImage"}, function(response) {});
});
});