Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

Code

// ==UserScript==
// @name        StackExchange Google Search
// @description Google questions if query begins with "gq:" and user profiles if query begins with "gu:".
// @version     1.1
// @include     http://stackoverflow.com/*
// @include     http://*.stackoverflow.com/*
// @include     http://serverfault.com/*
// @include     http://*.serverfault.com/*
// @include     http://superuser.com/*
// @include     http://*.superuser.com/*
// @include     http://stackexchange.com/*
// @include     http://*.stackexchange.com/*
// @include     http://stackapps.com/*
// @include     http://*.stackapps.com/*
// @include     http://askubuntu.com/*
// @include     http://*.askubuntu.com/*
// @include     http://answers.onstartups.com/*
// @include     http://*.answers.onstartups.com/*
// ==/UserScript==

document.getElementById("search").addEventListener("submit", function(event) {
    var query = document.getElementsByName("q")[0].value;
    if (!RegExp("^g[qu]:").test(query))
        return;
    event.preventDefault();
    document.location = "http://google.com/search?q=" +
        encodeURIComponent(query.substr(3)) +
        "+inurl:" +
        document.domain +
        ( (query.charAt(1) == "q") ? "/questions" : "/users" ) +
        "+site%3A" +
        document.domain +
        "+-site%3A*." +
        document.domain;
}, false);

About

With this User Script, you can override the built-in search with Google's.

Just begin type in your query as usual in the search in the upper right corner, but prefix it with gq: to google all questions or gu: to google all user profiles.

Examples:

  • gq:unicorn (finds a question with the word unicorn)
  • gq:"a unicorn" (finds a question with the phrase a unicorn)
  • gu:unicorn (finds all user profiles with the word unicorn)

License

I hereby release this script in the public domain.

Download

Click here to install this script.

Platform

This user script has been tested in Google Chrome 17.0.963.6 and Mozilla Firefox 8.0 with Greasemonkey 0.9.13.

share|improve this question
add comment

You must log in to answer this question.

Browse other questions tagged .