-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
52 lines (47 loc) · 1.92 KB
/
background.js
File metadata and controls
52 lines (47 loc) · 1.92 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
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.sendMessage(tab.id, { message: "clickRequest" }, function(response) {
console.log(response);
});
});
const contexts = ["page", "selection", "link", "editable", "image"];
for (let i = 0; i < contexts.length; i++) {
const context = contexts[i];
const title = "ClickAll";
chrome.contextMenus.create({"title": title, "contexts": [context],
"onclick": contextMenuCallback});
}
function contextMenuCallback(info, tab) {
chrome.tabs.sendMessage(tab.id, { message: "clickFromContext" }, function(response) {
console.log(response);
});
}
chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) {
let notificationId;
if (request.message === "clickRepetition") {
const options = { type: "basic", title: "ClickAll",
buttons: [{ title: "Yes"}, { title: "No, don't ask on this page again" }],
iconUrl: "https://inkspand.s3.amazonaws.com/assets/one-click-icon-193a10810ae09a9864fb306cdf7298a0.png",
message: "It looks like you're clicking a lot of similar elements. Would you like ClickAll to click the rest for you?" }
chrome.notifications.create(options, function(notificationIdString) {
notificationId = notificationIdString;
});
setTimeout(() => {
chrome.notifications.clear(notificationId);
}, 5000);
chrome.notifications.onClosed.addListener( (notificationId, byUser) => {
sendResponse({ message: "notificationTimedOut" });
});
chrome.notifications.onButtonClicked.addListener( (notificationId, buttonIndex) => {
if (buttonIndex === 0) {
sendResponse({ message: "clickAllRemaining" });
chrome.notifications.clear(notificationId);
return;
} else {
sendResponse({ message: "negativeUserResponse" });
chrome.notifications.clear(notificationId);
return;
}
});
}
return true;
});