// ==UserScript==
// @name Bing Bangs
// @namespace Bing Bangs
// @description Easily add DuckDuckGo bangs to Bing.
// @include *.bing.com/search*
// @version 1.1.1
// @grant none
// ==/UserScript==
var bangs=[],search=document.getElementById('sb_form_q').value;
//BANGS
new Bang('yt','https://youtube.com/feed/subscriptions','https://www.youtube.com/results?search_query=','+');
new Bang('ddg','https://duckduckgo.com','https://duckduckgo.com/?q=','+');
new Bang('so','https://stackoverflow.com','http://stackoverflow.com/search?q=','+');
new Bang('imdb','http://imdb.com','http://www.imdb.com/find?s=all&q=','+');
new Bang('gh','https://github.com','https://github.com/search?q=','+');
new Bang('gf','https://gf.qytechs.cn/scripts','https://gf.qytechs.cn/scripts/search?q=','+');
new Bang('gg','https://google.com','https://www.google.com/search?q=','+');
new Bang('zh','https://www.zhihu.com/topic','https://www.zhihu.com/search?q=','+');
new Bang('tb','https://taobao.com','https://s.taobao.com/search?q=','+');
new Bang('db','https://douban.com','https://www.douban.com/search?q=','+');
new Bang('bd','https://baidu.com','https://www.baidu.com/s?wd=','%20');
new Bang('bl','https://bilibili.com','https://search.bilibili.com/all?keyword=','%20');
new Bang('pc','https://www.pin-cong.com/local/search/page/','https://www.pin-cong.com/local/search/page/?q=','+');
//BANGS
for(var i in bangs){
var bang=bangs[i];
if(search.substr(0,bang.bang.substr(1).length+1)==bang.bang){
if(bang.urlSearch&&search.indexOf(' ')>=0)location.assign(bang.urlSearch+search.substr(bang.bang.length+1).replace(new RegExp(' ','g'),bang.spaceReplace));
else location.assign(bang.urlEmpty);
}
}
function Bang(bang,urlEmpty,urlSearch,spaceReplace){
this.bang='!'+bang;
this.urlEmpty=urlEmpty;
this.urlSearch=urlSearch;
this.spaceReplace=spaceReplace;
bangs.push(this);
}