forked from schue30/IDNDetector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
41 lines (35 loc) · 1.03 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
function setIcon(tabId) {
var canvas = document.createElement('canvas');
canvas.width = 19;
canvas.height = 19;
var context = canvas.getContext('2d');
context.fillStyle = '#e74c3c';
context.fillRect(0, 0, 19, 19);
context.fillStyle = '#FFFFFF';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.font = 'bold 16px Arial';
context.fillText('!', 10, 10);
chrome.pageAction.setIcon({
tabId: tabId,
imageData: context.getImageData(0, 0, 19, 19)
});
chrome.pageAction.show(tabId);
}
function checkForIDN(tabId, url) {
if (url !== punycode.toUnicode(url)) {
setIcon(tabId);
} else {
chrome.pageAction.hide(tabId);
}
}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
checkForIDN(tabId, tab.url);
});
chrome.tabs.onActivated.addListener(function(activeInfo) {
chrome.tabs.get(activeInfo.tabId, function(tab) {
if (tab && tab.url) {
checkForIDN(activeInfo.tabId, tab.url);
}
});
});