1

Recently a friend of mine noticed that I often open the first few Google results in tabs without looking at them first. Now I'd like to directly open the best Google results from the address bar. I know that it's possible to add custom search engines to the bar in the settings. However, how can I make Chrome open multiple tabs at once when using such a custom search engine?

2 Answers 2

0

You could perhaps run a webserver in the background which takes the query and passes it to a google "i'm feeling lucky" link. Opening more than one tab would obviously require you visting the website in chrome and explicitly allowing popups. To open the top 3(not only the first) search result, you will probably have to get the source code of the page(probably possible with either wget or links) and extract the search results from it. To only look for search results and avoid opening, say the gmail link, you may wish to filter out everything until the second hit of your search criteria.

Code for this would look something like this:

wget http://google.com/?q=$query -O $query.html
l=grep -n $query | head -c 1
head -cv $l
echo $source | grep '<a href='
for i in $l1 $l2 $l3; do google-chrome-unstable $i ;done

Note that my code is probably broken and I have no idea how to get the script to run without using command line, but maybe you could do it using a web2py server with the python system.os command.

Hope it helps

0

I know this is not exactly what you are looking for, but I made a bookmark with this JavaScript code in it, that opens the first 5 results from a Google search result in new tabs, if you are on the search result page:

javascript: (function (element, url) {
    element.src = url;
    element.onload = function () {
        jQuery.noConflict();
        var elements = jQuery("#search .g:nth-child(-n+4)>div>div>a:first-child");
        console.log("IN");
        jQuery.each(elements, function (key, element) {
            win = window.open(element.href, '_blank');
            console.log(key);
            if (key > 3) {
                console.log("IN");
                return false;
            }
            if (win) {
                win.focus();
            } else {
                alert('Please allow popups for this website');
            }
        })
    };
    document.head.appendChild(element);
})(document.createElement('script'), '//code.jquery.com/jquery-latest.min.js')

The .g:nth-child(-n+4) is where you can set the number of tabs, in this case it's 5.

Unfortunately Google changes the DOM structure every once in a while, so you need to adjust the code. Most of the time it's only a minuscule changes, where you have to swap one selector for another.

You create this kind of bookmark by adding a new bookmark and past this code as the "URL". Voilà!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .