Add 'Google' button to duckduckgo.com

Adds a 'Google' button below the search box to repeat the search at google

  1. // ==UserScript==
  2. // @name Add 'Google' button to duckduckgo.com
  3. // @description Adds a 'Google' button below the search box to repeat the search at google
  4. // @encoding utf-8
  5. // @namespace google_button_duckduckgo
  6. // @match *://duckduckgo.com/*
  7. // @grant none
  8. // @run-at document-end
  9. // @version 0.0.1.20190401105002
  10. // ==/UserScript==
  11.  
  12.  
  13. (function() {
  14. console.log('running');
  15. function searchOnGoogle() {
  16. var searchString = document.getElementById('search_form_input').value;
  17. document.location = "https://google.com/search?q=" + encodeURIComponent(searchString);
  18. }
  19. var elem = document.getElementsByClassName("header__content header__search")[0];
  20. if (elem && !document.getElementById('search_on_google')) {
  21. var div = document.createElement('div');
  22. div.id='search_on_google';
  23. var button = document.createElement('button');
  24. button.innerText = 'Google';
  25. button.onclick = searchOnGoogle
  26. div.appendChild(button);
  27. elem.appendChild(div);
  28. }
  29. })();