hoelz.ro - "Try Google" userscript for DuckDuckGo

"Try Google" userscript for DuckDuckGo

I love DuckDuckGo. Ninety-nine percent of the time, it gives me exactly what I want. But sometimes, I want to consult Google for its results. When DuckDuckGo doesn't come up with anything, it presents you with a link to do this, but with the following userscript, you can get a “Try this search on Google” link all the time!

try-google.user.js
  1. // ==UserScript==
  2. // @match http://duckduckgo.com/*
  3. // ==/UserScript==
  4.  
  5. (function() {
  6. var tryGoogleDiv = document.createElement('span');
  7. tryGoogleDiv.style.opacity = 0.6;
  8. tryGoogleDiv.style.backgroundColor = 'black';
  9. tryGoogleDiv.style.color = 'white';
  10. tryGoogleDiv.style.position = 'fixed';
  11. tryGoogleDiv.style.top = '65px';
  12. tryGoogleDiv.style.left = '10px';
  13. tryGoogleDiv.style.zIndex = 20000;
  14.  
  15. var form = document.getElementById('search_form');
  16. var inputs = form.getElementsByTagName('input');
  17. var q;
  18.  
  19. for(var i = 0; i < inputs.length; i++) {
  20. var input = inputs[i];
  21. if(input.name == 'q') {
  22. q = input;
  23. break;
  24. }
  25. }
  26. tryGoogleDiv.innerHTML = '<a href="http://google.com/search?q='
  27. + q.value + '" target="_blank" style="color: white">Try this same search with Google!</a>';
  28.  
  29. var parent = document.getElementById('content');
  30. parent.insertBefore(tryGoogleDiv, parent.firstChild);
  31. })();

Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki ipv6 ready