Super-phrase - automatic "phrase search" on DuckDuckGo.

Adds a verbatim tick-box to the DuckDuckGo search bar.

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Super-phrase - automatic "phrase search" on DuckDuckGo.
// @namespace    https://github.com/josefandersson/userscripts/
// @version      1.2
// @description  Adds a verbatim tick-box to the DuckDuckGo search bar.
//               When ticked, anything typed in the box is auto-wrapped 
//               in quote marks and thus "searched as a phrase".
//		 Works on main home-page only. Use to form your initial phrase,
//               then you add additional search keywords and knock-outs in the 
//               search-box on the results page.
// @author       Josef Andersson, under paid contract to myself.
// @author       Working regex for "phrase wrapping" then supplied to me by 
//               Fechinsir on Fivver, again under paid contract to myself.
// @match        https://duckduckgo.com/*

// @run-at       document-end
// ==/UserScript==

if (location.pathname === '/') {
    const test = document.getElementById('content_homepage');
    if (test == null) {
        return;
    }

    let form = document.getElementById('search_form_homepage');
    let input = form.querySelector('input');

    form.addEventListener('submit', ev => {
        if (localStorage.getItem('forceVerbatim') === 'true') {
            input.value = input.value.replace(/(^.*$)/g, '"$1"');
        }
    }, {
        capture: true
    });

    const div = document.createElement('div');
    const label = document.createElement('label');
    const checkbox = document.createElement('input');
    label.innerText = 'Verbatim';
    label.htmlFor = 'forceVerbatim'
    checkbox.id = 'forceVerbatim';
    checkbox.type = 'checkbox';
    checkbox.checked = localStorage.getItem('forceVerbatim') === 'true';
    div.appendChild(label);
    div.appendChild(checkbox);
    Object.assign(div.style, { margin:'-30px -3px 0 0', color:'#888', fontSize:'.8em', textAlign:'right' });
    Object.assign(checkbox.style, {})

    form.parentElement.insertBefore(div, form);

    checkbox.addEventListener('change', _ => {
        localStorage.setItem('forceVerbatim', checkbox.checked);
    });
}