// ==UserScript==
// @name          Search Wikipedia with Google
// @namespace     http://simon.incutio.com/code/greasemonkey/
// @description	  Alters Wikipedia search to use Google site: search instead.
// @include       http://*.wikipedia.org/*
// ==/UserScript==

/*

Here's the form we're modifying:

<form name="searchform" action="/wiki/Special:Search" id="searchform">  <input id="searchInput" name="search" type="text"    accesskey="f" value="" />  <input type='submit' name="go" class="searchButton" id="searchGoButton"    value="Go" />&nbsp;
  <input type='submit' name="fulltext"    class="searchButton"    value="Search" /></form>

*/

var form = document.getElementById('searchform');
var inputs = form.getElementsByTagName('input');
var input = inputs[0];
var go = inputs[1];
var search = inputs[2];
if (form && input && go && search) {
    // Move Go to the right
    form.appendChild(go);
    // Unbold it (by clearing its ID)
    go.id = '';
    // Search should be bold instead
    search.style.fontWeight = 'bold';
    // Update form to use Google
    form.action = 'http://www.google.com/search';
    input.name = 'as_q';
    // Add hidden q variable for site specific search
    var q = document.createElement('input');
    q.type = 'hidden';
    q.name = 'q';
    q.value = 'site:' + window.location.host;
    form.appendChild(q);
    // Set Go up to behave as normal
    go.onclick = function() {
      window.location = 'http://en.wikipedia.org/wiki/Special:Search?search=' + escape(input.value);
      return false;
    }
}
