Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DuckDuckGo UserScript
// ==UserScript==
// @name Google redirect for DuckDuckGo for Greasemonkey/Tampermonkey
// @namespace sscotth.io
// @description Adds a Google redirect link to your DuckDuckGo search results
// @include https://duckduckgo.com/?q=*
// @version 1
// @grant none
// ==/UserScript==
(() => {
const container = new DocumentFragment()
const li = document.createElement('li')
li.className = 'zcm__item'
li.id = 'google'
const a = document.createElement('a')
a.className = 'zcm__link'
li.appendChild(a)
const span_G = document.createElement('span')
span_G.className = 'blue'
span_G.innerText = 'G'
a.appendChild(span_G)
const span_o1 = document.createElement('span')
span_o1.className = 'red'
span_o1.innerText = 'o'
a.appendChild(span_o1)
const span_o2 = document.createElement('span')
span_o2.className = 'yellow'
span_o2.innerText = 'o'
a.appendChild(span_o2)
const span_g = document.createElement('span')
span_g.className = 'blue'
span_g.innerText = 'g'
a.appendChild(span_g)
const span_l = document.createElement('span')
span_l.className = 'green'
span_l.innerText = 'l'
a.appendChild(span_l)
const span_e = document.createElement('span')
span_e.className = 'red'
span_e.innerText = 'e'
a.appendChild(span_e)
const seperator = document.createElement('span')
seperator.id = 'duckbar_static_sep'
seperator.className = 'zcm__sep--h sep--before'
container.appendChild(li)
document.getElementById('duckbar_static').insertBefore(container,document.getElementById('duckbar_static').firstChild)
document.getElementById('duckbar_static_sep').classList.remove('is-hidden')
const style = document.createElement('style')
const styles = `
#google .red {
color: red
}
#google .blue {
color: blue
}
#google .green {
color: green
}
#google .yellow {
color: darkgoldenrod
}
#google span {
text-transform: none
}
`
style.innerText = styles
document.head.appendChild(style)
const updateQuery = () => a.href = 'https://google.com/search?q=' + encodeURIComponent(document.getElementById('search_form_input').value)
a.addEventListener('mousedown', updateQuery)
a.addEventListener('keydown', updateQuery)
updateQuery()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.