Skip to content

Instantly share code, notes, and snippets.

@hippietrail
Created December 2, 2012 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hippietrail/4186914 to your computer and use it in GitHub Desktop.
Save hippietrail/4186914 to your computer and use it in GitHub Desktop.
Convert a search on a StackExchange site to a Google search of that site
// ==UserScript==
// @name Hippietrail's StackExchange search to Google search
// @description Convert a search on a StackExchange site to a Google search of that site
// @version 0.0
// @namespace hippietrail
// @include http://stackoverflow.com/search*
// @include http://meta.stackoverflow.com/search*
// @include http://serverfault.com/search*
// @include http://meta.serverfault.com/search*
// @include http://superuser.com/search*
// @include http://meta.superuser.com/search*
// @include http://stackapps.com/search*
// @include http://*.stackexchange.com/search*
// @include http://meta.*.stackexchange.com/search*
// ==/UserScript==
function main() {
$('#bigsearch tr:last td:first').removeProp('colspan')
.parent().append('<td><input type="button" name="google" value="google"></td>');
$('input[name=google]').click(function (event) {
location.href =
'http://google.com'
+ location.pathname
+ location.search + '+site:' + location.hostname;
});
}
function addJsNode(func) {
'use strict';
var targ = document.getElementsByTagName('head')[0] || document.body || document.documentElement,
scriptNode = document.createElement('script');
scriptNode.type = 'text/javascript';
scriptNode.textContent = '(' + func.toString() + ')()';
targ.appendChild(scriptNode);
}
addJsNode(main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment