GoogleFullSearchButton

Add to the Google Full Search button.

目前為 2015-05-30 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name GoogleFullSearchButton
  3. // @name:zh-CN 谷歌全面搜索按钮
  4. // @namespace http://www.coofly.com/
  5. // @version 1.1
  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 /^https?://.+\.google\..+/.*$/
  11. // @exclude https://plus.google.*/*
  12. // @exclude http://plus.google.*/*
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. (function(){
  17. var intervalId = -1;
  18. var waitTime = 0;
  19. console.log('GoogleFullSearchButton执行, url = ' + location.href);
  20. function AddFullSearchButton ()
  21. {
  22. var abCtls = document.getElementById('ab_ctls');
  23. if (null === abCtls)
  24. {
  25. waitTime = waitTime + 200;
  26. if(waitTime >= 5000 && intervalId >= 0)
  27. {
  28. clearInterval(intervalId);
  29. console.log('GoogleFullSearchButton等待超时');
  30. }
  31. return;
  32. }
  33. else
  34. {
  35. if (intervalId >= 0){
  36. clearInterval(intervalId);
  37. console.log('intervalId已取消');
  38. }
  39. }
  40.  
  41. var targetUrl = '';
  42. var btnClass = '';
  43. if (location.href.indexOf('&safe=off') >= 0)
  44. {
  45. targetUrl = location.href.replace('&safe=off', '');
  46. btnClass = 'ab_button selected';
  47. }
  48. else
  49. {
  50. targetUrl = location.href + '&safe=off';
  51. btnClass = 'ab_button';
  52. }
  53. console.log('targetUrl = ' + targetUrl);
  54.  
  55. var buttonHtml = '<li class="ab_ctl"><a href="' + targetUrl + '" class="' + btnClass + '">全面搜索</a></li>';
  56.  
  57. abCtls.insertAdjacentHTML('afterbegin', buttonHtml);
  58. }
  59. var abCtls = document.getElementById('ab_ctls');
  60. if(null === abCtls)
  61. {
  62. intervalId = setInterval(AddFullSearchButton, 200);
  63. console.log('intervalId = ' + intervalId);
  64. return;
  65. }
  66. else
  67. {
  68. AddFullSearchButton();
  69. }
  70. })();