-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbackground.js
More file actions
55 lines (50 loc) · 1.5 KB
/
background.js
File metadata and controls
55 lines (50 loc) · 1.5 KB
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
52
53
54
55
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.action == 'new') {
chrome.tabs.create({ url: chrome.extension.getURL("search.html") + '?keyword=' + encodeURIComponent(request.keyword) });
}
else if (request.action == 'play') {
chrome.tabs.create({ url: chrome.extension.getURL("play.html") + '?url=' + encodeURIComponent(request.source) });
}
else if (request.action == 'load_source') {
sendResponse({ source: source })
}
}
)
chrome.commands.onCommand.addListener(function (command) {
if (command == "my_search_action") {
chrome.tabs.query({active:true}, function(tabs){
if(tabs[0].url.startsWith('chrome-extension://')){
chrome.tabs.sendMessage(tabs[0].id, {'action': 'search_selected'})
}else{
search_selected();
}
})
} else if (command == 'my_clean_action'){
cleanTabs();
}
});
function cleanTabs(){
chrome.tabs.query({url:'chrome-extension://'+chrome.runtime.id+'/*'}, function(tabs){
var tids = [];
for(let tab of tabs){
tids.push(tab.id);
}
chrome.tabs.remove(tids);
})
}
function search_selected(){
chrome.tabs.executeScript({
file: 'hotkeysearch.js'
});
}
chrome.contextMenus.create({
'title': "清空JaviJavi标签页",
'contexts': ["browser_action", "page"],
'onclick': cleanTabs
});
chrome.contextMenus.create({
'title': "搜索选择内容",
'contexts': ["browser_action", "page", "selection"],
'onclick': search_selected
});