-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
50 lines (45 loc) · 1.15 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
42
43
44
45
46
47
48
49
50
/**
* Background file of extension.
*
*/
chrome.runtime.onMessage.addListener((msg, sender, resp)=> {
/*TODO check condition for production environment.*/
var message = msg;
process(message);
return;
});
const FROM_WEB_PAGE = "CSS_REG_WEB_PAGE";
const FROM_EXT = "CSS_REG_EXT";
function process(message) {
if (message.from === FROM_WEB_PAGE) {
processWebPageMessage(message);
} else if (message.from = FROM_EXT) {
}
}
function processWebPageMessage(message) {
switch (message.type) {
case "MOCK_DATA":
addMockData();
break;
default:
console.log("Not Supported message type");
console.log(message);
}
}
function processExtensionMessage(message) {
}
function addMockData() {
var mockData = new MockData();
mockData.crateMockData()
.then((resp)=> {
runtimeSendMessage(resp);
}).catch((e)=> {
console.error(e);
});
}
function runtimeSendMessage(data) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, data, function(response) {
});
});
}