Bing Bangs

向必应Bing添加DuckDuckGo的Bang特性。

  1. // ==UserScript==
  2. // @name Bing Bangs
  3. // @namespace Bing Bangs
  4. // @description 向必应Bing添加DuckDuckGo的Bang特性。
  5. // @include *.bing.com/search*
  6. // @version 1.2
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. var bangs=[],search=document.getElementById('sb_form_q').value;
  11.  
  12. //BANGS
  13. new Bang('yt','https://youtube.com/feed/subscriptions','https://www.youtube.com/results?search_query=','+');
  14. new Bang('ddg','https://duckduckgo.com','https://duckduckgo.com/?q=','+');
  15. new Bang('so','https://stackoverflow.com','http://stackoverflow.com/search?q=','+');
  16. new Bang('imdb','http://imdb.com','http://www.imdb.com/find?s=all&q=','+');
  17. new Bang('gh','https://github.com','https://github.com/search?q=','+');
  18. new Bang('gf','https://greasyfork.org/scripts','https://greasyfork.org/scripts/search?q=','+');
  19. new Bang('gg','https://google.com','https://www.google.com/search?q=','+');
  20. new Bang('zh','https://www.zhihu.com/topic','https://www.zhihu.com/search?q=','+');
  21. new Bang('tb','https://taobao.com','https://s.taobao.com/search?q=','+');
  22. new Bang('db','https://douban.com','https://www.douban.com/search?q=','+');
  23. new Bang('bd','https://baidu.com','https://www.baidu.com/s?wd=','%20');
  24. new Bang('bl','https://bilibili.com','https://search.bilibili.com/all?keyword=','%20');
  25. new Bang('wb','http://s.weibo.com/','http://s.weibo.com/weibo/','%2520');
  26. //BANGS
  27.  
  28. for(var i in bangs){
  29. var bang=bangs[i];
  30. if(search.charAt(0) == '!' || search.charAt(0) == "!" )
  31. {
  32. if(search.substr(1,bang.bang.substr(0).length)==bang.bang)
  33. {
  34. if(bang.urlSearch&&search.indexOf(' ')>=0)location.assign(bang.urlSearch+search.substr(bang.bang.length+2).replace(new RegExp(' ','g'),bang.spaceReplace));
  35. else location.assign(bang.urlEmpty);
  36. }
  37. }
  38. }
  39.  
  40. function Bang(bang,urlEmpty,urlSearch,spaceReplace){
  41. this.bang=bang;
  42. this.urlEmpty=urlEmpty;
  43. this.urlSearch=urlSearch;
  44. this.spaceReplace=spaceReplace;
  45. bangs.push(this);
  46. }