-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddg-quick-bang.user.js
44 lines (38 loc) · 1.11 KB
/
ddg-quick-bang.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// ==UserScript==
// @name Duckduckgo quick bang
// @namespace http://taiho.moe/
// @version 0.1
// @description Quick jump to startpage & google
// @author swordfeng
// @match https://duckduckgo.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const searchBars = $('ul#duckbar_static');
if (searchBars) {
appendToSearchBar(searchBars[0]);
}
})();
function appendToSearchBar(bar) {
appendBang(bar, 's');
appendBang(bar, 'g');
}
function appendBang(bar, bang) {
const bangLink = document.createElement('a');
bangLink.className = 'zcm__link';
bangLink.innerHTML = '!' + bang;
bangLink.href = '#';
bangLink.addEventListener('click', () => {
const search = '!' + bang + ' ' + getSearch();
window.location.search = '?q=' + encodeURIComponent(search);
});
const bangItem = document.createElement('li');
bangItem.className = 'zcm__item';
bangItem.appendChild(bangLink);
bar.appendChild(bangItem);
}
function getSearch() {
const searchBox = $('input[name="q"]')[0];
return searchBox.value;
}