Last active
April 16, 2017 11:39
-
-
Save gekola/6aab5fcaadc75e34b598 to your computer and use it in GitHub Desktop.
DuckDuckGoogle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name DuckDuckGoogle | |
// @description Add Google search button to DuckDuckGo search form | |
// @namespace github.com/gekola | |
// @version 0.1.2 | |
// @author Nick H | |
// @license WTFPL | |
// @released 2016-03-12 | |
// @updated 2017-04-16 | |
// @match *://duckduckgo.com/* | |
// @match *://www.duckduckgo.com/* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
document.addEventListener('DOMContentLoaded', function () { | |
var form = document.getElementsByClassName('header__search')[0]; | |
if ((form === null) || (document.getElementById('google_search') !== null)) { | |
return; | |
} | |
var style = document.createElement('STYLE'); | |
//style.innerHTML = '.search_form { right: 14px !important; }' | |
document.head.appendChild(style); | |
var gsearchBtn = document.createElement('BUTTON'); | |
gsearchBtn.innerHTML = 'G'; | |
gsearchBtn.id = 'google_search'; | |
var GBUTTON_STYLE = { | |
backgroundColor: '#4787ed', | |
border: '1px solid #3079ed', | |
borderRadius: '2px', | |
color: '#ffffff', | |
cursor: 'pointer', | |
height: 'auto', | |
fontSize: '18px', | |
fontWeight: 'bold', | |
lineHeight: 1.5, | |
margin: '3px 0 0 5px', | |
float: 'left', | |
position: 'absolute', | |
right: '-36px', | |
top: 0, | |
width: 'auto' | |
}; | |
for (var attr in GBUTTON_STYLE) { | |
gsearchBtn.style[attr] = GBUTTON_STYLE[attr]; | |
} | |
gsearchBtn.addEventListener('click', function(e) { | |
e.preventDefault(); | |
var q = document.getElementById('search_form_input').value; | |
document.location = '//google.com/search?q=' + encodeURI(q); | |
}); | |
form.appendChild(gsearchBtn); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment