In Google Chrome, if I select a piece of text and right click on it, I get the option to:
'Search Google for [text]'
I find this extremely useful but I'd also like to be able to add my own options.
For example, I'd like to add the ability to search amazon.co.uk using the selected text or go straight to Google maps using the selected text (i.e. an address or postcode) and so on.
I can sort of add this functionality using PhraseExpress but would rather be able to do it straight from Chrome - is it possible?
16 Answers
Here's an extension that uses the Context Menus API to add options to the right click menu for selected text and lets you define your own custom searches.
Try for Google Maps and for Amazon.co.uk.
3There's a Context Menus API available in the developer and beta channels as of recently. You can use it to write your own extensions which add options to the right click menu. Note that this will only work for Google Chrome version 6 and higher.
Here's an example from the official extensions gallery:
- Imgur Uploader (upload an image to Imgur on right click)
I also wrote three of my own, based on that code:
- TinEye Right Click (perform a reverse image search at TinEye on right click)
- Wikipedia Right Click (search for articles about selected text at Wikipedia on right click)
- Merriam-Webster Right Click (look up definition of selected text at Merriam-Webster on right click)
You can install those at your own risk by right clicking the links, clicking Save Link As…, finding the files on your computer, and dragging them into a Google Chrome window.
Read about the API here:
To write your own, you need a manifest.json file, which should look something like this:
{ "background_page": "background.html", "description": "Add a context menu item to search for selected text at Google Maps.", "icons": { "16": "icon16.png", "48": "icon48.png" }, "minimum_chrome_version": "6", "name": "Google Maps Right Click", "permissions": [ "contextMenus", "tabs" ], "version": "1.0"
}You also need a background.html file, which should look something like this:
<script>
function searchgooglemaps(info)
{ var searchstring = info.selectionText; chrome.tabs.create({url: "" + searchstring})
}
chrome.contextMenus.create({title: "Search Google Maps", contexts:["selection"], onclick: searchgooglemaps});
</script>Lastly, you should have at least a 16 × 16 pixel icon for the context menu and a 48 × 48 pixel icon for the extensions management page. You can also specify a 128 × 128 pixel icon, which is shown during installation, and a 32 × 32 pixel icon if you want to submit your extension to the official gallery. All of your icons need to be listed in manifest.json. Make sure file types and names match up.
Put the icons, background.html, and manifest.json in a folder together, then go to the extensions management page at chrome://extensions, look under Developer mode (I think you need to be running the beta channel or higher for this to show up), click on Pack extension…, next to Extension root directory click Browse…, locate and select the folder you made, click OK, and drag the resulting .crx file into your Google Chrome window.
There is a Context Search extension which does what you want with an exception that it does not add anything to the right click menu; instead, after you select a chunk of text on page, it will show a small button with blue triangle next to it, and clicking on it will pop up menu.
I've been enjoying an extension called Custom Right-Click MenuIt allows you to create fully configurable right-click menu items, and even works in other browsers (Opera: Install Chrome Extensions, Firefox: Chrome Store Foxified).
Install "Custom Right-Click Menu" from the Chrome Store
Open the Options for Custom Right-Click Menu
In the Editing the CRM section, select Selection
Scroll down to Commonly Used Search Engines, and add one
It adds that search engine in the Editing the CRM section.
Click on it, not on its gear, to edit it.
Change the name to "Search amazon.co.uk" or whatever
Change the code to
var query; var url = ""; if (crmAPI.getSelection()) { query = crmAPI.getSelection(); } else { query = window.prompt('Please enter a search query.'); } if (query) { window.open(url.replace(/%s/g,query), '_blank'); }Create another menu item of the script type, call it "Google Map" or whatever, and code it the same way:
var query; var url = ""; if (crmAPI.getSelection()) { query = crmAPI.getSelection(); } else { query = window.prompt('Please enter a search query.'); } if (query) { window.open(url.replace(/%s/g,query), '_blank'); }
There is an extension called "Context Menu Search". It lets you add URLs to it, and then when you select a text, and click one of the URLs, it passes that text to the URL you clicked.
For example, the search URL for YouTube is:
where TESTSEARCH is the text you want to search for. In the extension, you add this line and it'll automatically replace TESTSEARCH with the selected text when you press it. You can ofcourse add a label for each URL.
Here is the link to the extension.
Hi since the main question has been answered I want to contribute with something.
This is a simply modified script similar to reverse image search with google but redirects imglink.jpg to Jeffrey's Exif Viewer to analyze the EXIF of an image.
Thanks to gdejohn.
Easy, create this 2 files I used notepad, add some icons 16x16, 48x48 and 128x128 (or delete line) and go to chrome://extensions/ tick developer mode add the containing folder of the files.
Filename: manifest.json
{
"manifest_version": 2, "background" : { "scripts": ["background.js"] }, "description": "Agrega un menu contextual para ver el EXIF de imagenes. Jeffrey's Exif Viewer", "icons": { "16": "icon16.png", "48": "icon48.png", "128": "icon128.png" }, "minimum_chrome_version": "6", "name": "Regex Exif Viewer Right Click", "permissions": [ "contextMenus", "tabs", "", "" ], "version": "1.0"
}Filename: background.js
/** * Returns a handler which will open a new tab when activated. */
function getClickHandler() { return function(info, tab) { // The srcUrl property is only available for image elements.
var url = "" + info.srcUrl; // Create a new tabto the info page.
chrome.tabs.create({ url: url, }); };
};
/** * Create a context menu which will only show up for images. */
chrome.contextMenus.create({ "title" : "Get image info via Jeffrey's Exif Viewer", "type" : "normal", "contexts" : ["image"], "onclick" : getClickHandler()
});