Skip to content

Instantly share code, notes, and snippets.

@spudtrooper
Created February 13, 2012 14:19
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 spudtrooper/1817223 to your computer and use it in GitHub Desktop.
Save spudtrooper/1817223 to your computer and use it in GitHub Desktop.
Redirects google searches starting with bang to duckduckgo.com. This way you can keep google (or whatever) as your default search engine so that when you 'cat' in the address bar, google is searched. But, when you type '!yt cat', youtube is searched, bec
// ==UserScript==
// @name Google + DuckDuckGo
// @namespace http://jeffpalm.com/googleduckduckgo/
// @description Redirects google searches starting with bang to duckduckgo.com
// @include https://www.google.com/*
// @include http://www.google.com/*
// ==/UserScript==
(function() {
function cgiParams(url) {
var path = url.replace(/.*\?/,'');
var pairs = path.split(/&/);
var res = {};
for (var i=0; i<pairs.length; i++) {
var p = pairs[i].split(/=/);
var k,v;
if (p.length == 2) {
k = p[0];
v = p[1];
} else {
k = p[0];
v = "";
}
res[k] = v;
}
return res;
}
function main() {
var url = String(document.location);
var params = cgiParams(url);
var q = params['q'];
if (!!q) {
if (q.match(/^!/)) {
document.location = 'https://duckduckgo.com/?q=' + q;
}
}
}
main();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment