-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
29 lines (25 loc) · 877 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
chrome.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({
id: "default",
title: chrome.i18n.getMessage('default_menu'),
type: 'normal',
contexts: ['selection'],
});
chrome.contextMenus.create({
id: "edit",
title: chrome.i18n.getMessage('edit_menu'),
type: 'normal',
contexts: ['selection'],
});
});
chrome.contextMenus.onClicked.addListener(function(item, tab) {
let selectedText = item.selectionText;
if (item.menuItemId == 'edit') {
selectedText = prompt(chrome.i18n.getMessage('prompt_message'), selectedText);
if (selectedText == null) {
return;
}
}
let url = 'https://'+ chrome.i18n.getMessage('url') +'/search?q=' + encodeURIComponent(selectedText);
chrome.tabs.create({url: url, index: tab.index + 1});
});