-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventPage.js
45 lines (41 loc) · 1.77 KB
/
eventPage.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
// event page 维护Controller的实例,供其他content script通过connect port调用
var eomnibarController = new Controller();
// Long-lived connections
chrome.runtime.onConnect.addListener(function(port) {
if (port.name == 'eomnibarPort') {
port.onMessage.addListener(function(msg) {
console.log(msg);
if (msg.action === 'performSearch') {
const suggestions = eomnibarController.performSearch(
msg.queryString, msg.maxSuggestion);
port.postMessage({queryString: msg.queryString, suggestions: suggestions});
} else if (msg.action === 'loginWithEvernote') {
eomnibarController.loginWithEvernote();
}
});
}
});
// Simple one-time requests
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === 'hide') {
console.log('hide the iframe');
//chrome.runtime.sendMessage({action: 'hideOut'});
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
action: 'hideOut'});
});
} else if (request.action === 'loadAllNotes') {
eomnibarController.loadAllNotes();
} else if (request.action === 'openInNewTab') {
chrome.tabs.create({url: request.url});
} else if (request.action === 'openInCurrentTab'){
chrome.tabs.update({url: request.url});
} else if (request.action === 'performSearch') {
const suggestions = eomnibarController.performSearch(
request.queryString, request.maxSuggestion);
sendResponse({suggestions: suggestions});
}
});
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({url:"main.html"});
});