-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
33 lines (29 loc) · 1.15 KB
/
index.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
/** Add a search menu, restricted to MDN */
var mdnUrl = 'https://developer.mozilla.org';
/** Google query URL with btnI key which activates I'm Feeling Lucky */
var googleUrl = 'https://google.com/search?btnI&q=';
/** Returns a Google query URL using I'm Feeling Lucky given an unformatted
query and optional domain string to restict the search to */
function getLucky (query, site) {
site = site ? ['site:', site, '+'].join('') : '';
return [googleUrl, site, query].join('');
}
/** Creates a new item in the context menu to open the top search result on a
given site for the text selection on the page */
chrome.contextMenus.create({
title: 'MDNJump',
contexts: ['selection'],
onclick: function (evt) {
var query = evt.selectionText;
var luckyUrl = getLucky(query, mdnUrl);
chrome.tabs.create({ url: luckyUrl });
}
});
/** Add basic omnibox functionality */
chrome.omnibox.setDefaultSuggestion({
description: 'Press ENTER to jump to the top MDN page for: %s'
});
chrome.omnibox.onInputEntered.addListener(function (query) {
var luckyUrl = getLucky(query, mdnUrl);
chrome.tabs.update({ url: luckyUrl });
});