谷歌全面搜索按钮

给Google添加上全面搜索按钮。

目前为 2015-05-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GoogleFullSearchButton
  3. // @name:zh-CN 谷歌全面搜索按钮
  4. // @namespace http://www.coofly.com/
  5. // @version 1.0
  6. // @description Add to the Google Full Search button.
  7. // @description:zh-cn 给Google添加上全面搜索按钮。
  8. // @author Coofly
  9. // @match http://tampermonkey.net/scripts.php
  10. // @include http://*.google.*/search*
  11. // @include https://*.google.*/search*
  12. // @include http://*.google.*/webhp*
  13. // @include https://*.google.*/webhp*
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. (function(){
  18. var intervalId = -1;
  19. function AddFullSearchButton ()
  20. {
  21. var abCtls = document.getElementById('ab_ctls');
  22. if (null === abCtls) return;
  23. if (intervalId >= 0){
  24. clearInterval(intervalId);
  25. console.log('intervalId已取消');
  26. }
  27.  
  28. var targetUrl = '';
  29. var btnClass = '';
  30. if (location.href.indexOf('&safe=off') >= 0)
  31. {
  32. targetUrl = location.href.replace('&safe=off', '');
  33. btnClass = 'ab_button selected';
  34. }
  35. else
  36. {
  37. targetUrl = location.href + '&safe=off';
  38. btnClass = 'ab_button';
  39. }
  40. console.log('targetUrl = ' + targetUrl);
  41.  
  42. var buttonHtml = '<li class="ab_ctl"><a href="' + targetUrl + '" class="' + btnClass + '">全面搜索</a></li>';
  43.  
  44. abCtls.insertAdjacentHTML('afterbegin', buttonHtml);
  45. }
  46. var abCtls = document.getElementById('ab_ctls');
  47. if(null === abCtls)
  48. {
  49. intervalId = setInterval(AddFullSearchButton, 100);
  50. console.log('intervalId = ' + intervalId);
  51. return;
  52. }
  53. else
  54. {
  55. AddFullSearchButton();
  56. }
  57. })();