-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
48 lines (44 loc) · 996 Bytes
/
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
function clickFreePrint(link) {
chrome.tabs.query({
active: true,
currentWindow: true
}, (tabs) => {
if (tabs.length !== 1) {
return;
}
chrome.tabs.update(tabs[0].id, {
url: link
}, (tab) => {
setTimeout(() => {
chrome.tabs.sendMessage(tab.id, {
text: 'click_free_print_button'
}, (link) => {
chrome.tabs.update(tabs[0].id, {
url: link
})
});
}, 500);
});
});
}
function handleLicenseLink(link) {
if (!link) {
return;
}
chrome.tabs.create({
url: link
}, (tab) => {
const clickPrintButton = {
text: 'click_license_print_button'
}
setTimeout(() => {
chrome.tabs.sendMessage(tab.id, clickPrintButton, clickFreePrint);
}, 1000)
})
}
chrome.browserAction.onClicked.addListener(function (tab) {
const getLicenseLink = {
text: "get_license_link"
}
chrome.tabs.sendMessage(tab.id, getLicenseLink, handleLicenseLink);
});