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

  1. Create a folder

  2. 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/

  3. 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
  1. 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