-
Notifications
You must be signed in to change notification settings - Fork 3
/
fontblocker.background.js
51 lines (45 loc) · 1.3 KB
/
fontblocker.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
function setPageActionIcon(tabId, disabled) {
var icon = disabled ? '128x128-disabled' : '128x128';
chrome.pageAction.setIcon({
tabId: tabId,
path: chrome.runtime.getURL('images/' + icon + '.png'),
});
}
// Context menu: BLOCK ALWAYS
chrome.contextMenus.create({
"title": 'Block custom font',
"contexts": ["page", "frame", "selection", "link", "editable"],
"onclick": function(info, tab) {
chrome.tabs.sendMessage(tab.id, {getLastElementFont: true}, function(data) {
// Not as response, bc async, so instead as new message
// blockFont(data);
});
}
});
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if ( msg && msg.blockFont ) {
blockFont(msg.blockFont);
}
});
function blockFont(data) {
if ( !data || !data.name || !data.host ) return;
console.debug('Saving font', data);
fb.exists(data, function(exists) {
if (!exists) {
fb.add(data);
}
});
}
// Show page action
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if ( msg && msg.fontsBlocked ) {
setPageActionIcon(sender.tab.id);
chrome.pageAction.show(sender.tab.id);
}
});
// Click on page action
chrome.pageAction.onClicked.addListener(function(tab) {
chrome.tabs.sendMessage(tab.id, {glimpseFonts: true}, function(data) {
setPageActionIcon(tab.id, data.disabled);
});
});