Skip to content

Instantly share code, notes, and snippets.

@josefandersson
Created August 28, 2020 19:26
Show Gist options
  • Save josefandersson/ec79cc2d497f90be77a776dbc54ec2df to your computer and use it in GitHub Desktop.
Save josefandersson/ec79cc2d497f90be77a776dbc54ec2df to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name DuckDuckGo Verbatim
// @namespace https://github.com/josefandersson/userscripts/
// @version 1.1
// @description Adds a verbatim button to the duckduckgo search bar
// @author Josef Andersson
// @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);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment