UnDuckButton

A botton that redirects DuckDuckGo searches to Startpage

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        UnDuckButton
// @namespace   Violentmonkey Scripts
// @match       https://duckduckgo.com/*
// @grant       none
// @version     0.1.1
// @author      noarch
// @description A botton that redirects DuckDuckGo searches to Startpage
// @license     WTFPL

// ==/UserScript==

var styles = "#redirector {display: block; margin: 64px auto auto 16px; height: 32px; right: 6px; position: absolute; bottom: 0; top: 0;}";
var styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);

function addButton(text, href) {
    var btn = document.createElement("BUTTON");
    btn.innerHTML = text;
    btn.id = "redirector";
    btn.onclick = function() {
         window.location = href;
    };
    document.getElementById("header_wrapper").appendChild(btn);
}

function getSearchQuery() {
    var input = document.getElementById("search_form_input").value;
    var inputEncoded = encodeURIComponent(input);
    return "https://startpage.com/sp/search?query=" + inputEncoded;
}

try {
    var searchQuery = getSearchQuery();
} catch (error) {
    return false;
}

addButton("Search on Startpage", searchQuery);