rust-search-extension/extension/main.js

33 lines
913 B
JavaScript
Raw Normal View History

2018-11-03 07:45:04 +00:00
setup();
function setup() {
chrome.omnibox.setDefaultSuggestion({
description: "Search Rust official docs or crates for <match>%s</match>"
});
chrome.omnibox.onInputChanged.addListener(function(query, suggestFn) {
console.log('suggest:', query);
suggestFn([
{
content: "https://doc.rust-lang.org/stable/std/?search=" + query,
description: "Docs - <dim>std::</dim>" + "<match>" + query + "</match>"
},
]);
});
chrome.omnibox.onInputEntered.addListener(function(text) {
if (text.match(/^https?\:/)) {
navigateToUrl(text);
} else {
navigateToUrl('https://crates.io/search?q=' + encodeURIComponent(text));
}
});
}
function navigateToUrl(url) {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.update(tab.id, {url: url});
});
}