A whim
After the text is selected, click the right button, the browser’s right button menu only ‘use Baidu search’ a search engine
Suddenly I wanted to add Google.
The final result
You need to develop a browser extension, and the steps are relatively simple
-
Create a folder
-
Create a manifest.json file in your folder. It should be called this, and the browser will recognize it
The file content
{" name ":" gaga ", "version" : "1.0", "manifest_version" : 2, "ICONS" : {" 16 ":" image/express. PNG ", "48" : PNG ", "128": "image/cute. PNG ", "description": "cute ", "background": {"scripts": [ "background.js" ] }, "permissions": [ "contextMenus" ] }Copy the code
Those lovely little ICONS are ICONS from www.iconfont.cn/
-
Create a new js file background-js
const googleEngine = {
link: 'https://www.google.com/search?q=',
}
chrome.contextMenus.create({
type: 'normal'.title: 'Use Google search -> "%s"'.// %s indicates the selected text
id: 'google'.contexts: ['selection']
})
chrome.contextMenus.onClicked.addListener(parameter= > {
const { selectionText } = parameter
chrome.tabs.create({ url: googleEngine.link + selectionText })
})
Copy the code
- Chrome :// Extensions/Open the home page of the extension -> Load the unzipped extension -> select the folder just found
Work together!!
tips
Click here to continue development and debugging, remember to refresh each time