Added an example of the search API (#372)

* Added an example of the search API

* Fix manifest.json
This commit is contained in:
wbamberg
2018-10-12 11:22:27 -07:00
committed by GitHub
parent fc73e0088f
commit 04ab5ab0e4
7 changed files with 75 additions and 0 deletions

26
menu-search/background.js Normal file
View File

@@ -0,0 +1,26 @@
/*
Create a menu item for each installed search engine.
The ID and title are both set to the search engine's name.
*/
function createMenuItem(engines) {
for (let engine of engines) {
browser.menus.create({
id: engine.name,
title: engine.name,
contexts: ["selection"]
});
}
}
browser.search.get().then(createMenuItem);
/*
Search using the search engine whose name matches the
menu item's ID.
*/
browser.menus.onClicked.addListener((info, tab) => {
browser.search.search({
query: info.selectionText,
engine: info.menuItemId
});
});