-
Notifications
You must be signed in to change notification settings - Fork 0
/
listeners.js
38 lines (34 loc) · 1.12 KB
/
listeners.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
const { readFromClipboard, copyToClipboard } = require("./functions");
const iconRedPaths = {
16: "images/icon16red.png",
24: "images/icon24red.png",
32: "images/icon32red.png",
48: "images/icon48red.png",
128: "images/icon128red.png",
};
const iconGreenPaths = {
16: "images/icon16green.png",
24: "images/icon24green.png",
32: "images/icon32green.png",
48: "images/icon48green.png",
128: "images/icon128green.png",
};
// ref: https://stackoverflow.com/a/39909282/8556340
chrome.tabs.onUpdated.addListener(function (_tabId, changeInfo, _tab) {
if (changeInfo.status == "complete") {
chrome.browserAction.setIcon({ path: iconRedPaths });
chrome.browserAction.setPopup({ popup: "" });
}
});
chrome.browserAction.onClicked.addListener(function (_tab) {
try {
var originalUrl = readFromClipboard();
var decodedUrl = decodeURIComponent(originalUrl);
copyToClipboard(decodedUrl);
chrome.browserAction.setIcon({ path: iconGreenPaths });
chrome.browserAction.setPopup({ popup: "./info.html" });
} catch (error) {
chrome.browserAction.setPopup({ popup: "./fail.html" });
return;
}
});