UnDuckButton

Buttons that redirect DuckDuckGo searches to other search engines.

当前为 2021-02-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name UnDuckButton
  3. // @namespace Violentmonkey Scripts
  4. // @match https://duckduckgo.com/*
  5. // @grant none
  6. // @version 0.2
  7. // @author noarch
  8. // @description Buttons that redirect DuckDuckGo searches to other search engines.
  9. // @license WTFPL
  10.  
  11. // ==/UserScript==
  12.  
  13.  
  14. // Searx instances from https://searx.neocities.org/nojs.html
  15. // Updated 2021-01-15
  16. var searxes = [
  17. "https://searx.ir/?q=",
  18. "https://search.stinpriza.org/?q=",
  19. "https://search.privacytools.io/searx/?q=",
  20. "https://search.azkware.net/?q=",
  21. "https://searx.openpandora.org/?q=",
  22. "https://trovu.komun.org/?q=",
  23. "https://searx.nakhan.net/?q=",
  24. "https://searx.nixnet.services/?q=",
  25. "https://searx.libmail.eu/?q=",
  26. "https://searx.elukerio.org/?q=",
  27. "https://searx.info/?q=",
  28. "https://searx.foo.li/?q="
  29. ];
  30. var randomSearx = searxes[Math.floor(Math.random() * searxes.length)];
  31.  
  32. // Add more search engines here
  33. var searchEngines = {
  34. "Bing": "https://www.bing.com/search?q=",
  35. "Google": "https://www.google.com/search?q=",
  36. "Random Searx": randomSearx,
  37. "Startpage": "https://startpage.com/sp/search?query="
  38. };
  39.  
  40. function getSearchQuery() {
  41. var input = document.getElementById("search_form_input").value;
  42. var inputEncoded = encodeURIComponent(input);
  43.  
  44. return inputEncoded;
  45. }
  46.  
  47. function addButton(text, href) {
  48. var btn = document.createElement("button");
  49. btn.innerHTML = text;
  50. btn.onclick = function() {
  51. window.location = href;
  52. };
  53.  
  54. return btn;
  55. }
  56.  
  57. function main() {
  58. // Create styles for the <div> containing the buttons
  59. var styles = ".redirectors {display: block; margin: 60px auto auto auto; right: 4px; position: absolute; bottom: 0; top: 0;}";
  60. var styleSheet = document.createElement("style");
  61. styleSheet.type = "text/css";
  62. styleSheet.innerText = styles;
  63.  
  64. searchQuery = getSearchQuery(); // Failing here (if not on a result page) is fine, and intended
  65.  
  66. var div = document.createElement("div");
  67. div.classList.add("redirectors");
  68.  
  69. for (var searchEngine in searchEngines) {
  70. href = searchEngines[searchEngine] + searchQuery;
  71. div.appendChild(addButton(searchEngine, href));
  72. }
  73.  
  74. document.head.appendChild(styleSheet);
  75. document.getElementById("header_wrapper").appendChild(div);
  76. }
  77.  
  78. main();