UnDuckButton

A botton that redirects DuckDuckGo searches to Startpage

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

  1. // ==UserScript==
  2. // @name UnDuckButton
  3. // @namespace Violentmonkey Scripts
  4. // @match https://duckduckgo.com/*
  5. // @grant none
  6. // @version 0.1.1
  7. // @author noarch
  8. // @description A botton that redirects DuckDuckGo searches to Startpage
  9. // @license WTFPL
  10.  
  11. // ==/UserScript==
  12.  
  13. var styles = "#redirector {display: block; margin: 64px auto auto 16px; height: 32px; right: 6px; position: absolute; bottom: 0; top: 0;}";
  14. var styleSheet = document.createElement("style");
  15. styleSheet.type = "text/css";
  16. styleSheet.innerText = styles;
  17. document.head.appendChild(styleSheet);
  18.  
  19. function addButton(text, href) {
  20. var btn = document.createElement("BUTTON");
  21. btn.innerHTML = text;
  22. btn.id = "redirector";
  23. btn.onclick = function() {
  24. window.location = href;
  25. };
  26. document.getElementById("header_wrapper").appendChild(btn);
  27. }
  28.  
  29. function getSearchQuery() {
  30. var input = document.getElementById("search_form_input").value;
  31. var inputEncoded = encodeURIComponent(input);
  32. return "https://startpage.com/sp/search?query=" + inputEncoded;
  33. }
  34.  
  35. try {
  36. var searchQuery = getSearchQuery();
  37. } catch (error) {
  38. return false;
  39. }
  40.  
  41. addButton("Search on Startpage", searchQuery);