Skip to content

Instantly share code, notes, and snippets.

@m-thomson
Created May 27, 2020 15:52
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 m-thomson/611d8a91dcc27008dd4fc404d5bc3d94 to your computer and use it in GitHub Desktop.
Save m-thomson/611d8a91dcc27008dd4fc404d5bc3d94 to your computer and use it in GitHub Desktop.
Adds a 'Google' button below the DDG search box to retry the search at Google using !g
// ==UserScript==
// @name Add 'Google' button to duckduckgo.com
// @description Adds a 'Google' button below the DDG search box to retry the search at Google using !g
// @encoding utf-8
// @namespace google_button_duckduckgo
// @match *://duckduckgo.com/*
// @grant none
// @run-at document-end
// @version 0.0.1.20190401105002
// ==/UserScript==
(function() {
function searchOnGoogle() {
var searchString = document.getElementById('search_form_input').value;
document.location = "https://google.com/search?q=" + encodeURIComponent(searchString);
}
var elem = document.getElementsByClassName("header__content header__search")[0];
if (elem && !document.getElementById('search_on_google')) {
var div = document.createElement('div');
div.id='search_on_google';
var button = document.createElement('button');
button.innerText = 'Google';
button.onclick = searchOnGoogle
div.appendChild(button);
elem.appendChild(div);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment