-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
36 lines (31 loc) · 886 Bytes
/
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
/* global chrome */
var data;
// Trigger content script
function createGuide() {
chrome.tabs.executeScript(null, {
file: '/content_scripts/generate.js',
}, () => {
if (chrome.runtime.lastError)
console.error(chrome.runtime.lastError.message);
}).catch(e => {
if (e.message && /Missing host permission for the tab/.test(e.message))
window.alert('This addon does not work in this tab');
else
throw e;
});
}
// Open new tab with style guide
function openGuide(message) {
if (message.response) {
chrome.runtime.sendMessage(data);
} else {
data = message;
chrome.tabs.create({
'url': chrome.extension.getURL('styleguide.html'),
});
}
}
// browser action button listener
chrome.browserAction.onClicked.addListener(createGuide);
// listener for content-scripts message
chrome.runtime.onMessage.addListener(openGuide);