Quick search & Go to Top -- Google

Add 'quick search' input and 'go to top' button for Google

当前为 2015-09-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Quick search & Go to Top -- Google
  3. // @namespace feifeihang.info
  4. // @description Add 'quick search' input and 'go to top' button for Google
  5. // @include https://www.google.*
  6. // @include http://www.google.*
  7. // @version 5.1
  8. // @grant none
  9. // ==/UserScript==
  10. (function (window, document, undefined) {
  11. var container = document.createElement('div');
  12. container.style = 'display: none; position: fixed; bottom: 20px;' +
  13. 'right: 5px; text-align: right;' +
  14. 'width: 280px; height: 60px; z-index: 999999999;' +
  15. 'opacity: 0.8;';
  16. container.addEventListener('mouseenter', function () {
  17. this.style.opacity = '1';
  18. }, true);
  19. container.addEventListener('mouseout', function () {
  20. this.style.opacity = '0.8';
  21. }, true);
  22. // create quick query input.
  23. var input = document.createElement('input');
  24. input.tyle = 'text';
  25. input.value = document.querySelector('#lst-ib').value;
  26. input.setAttribute('placeholder', 'Search...');
  27. input.style = 'border: none; border-left: solid #EA4335 5px; flex: 1; display: inline-block; outline: none; height: 40px;' +
  28. 'font-size: 15px; margin-top: 10px; margin-bottom: 10px; padding: 0; ' +
  29. 'padding-left: 10px; padding-right: 10px; background: #D9D9D9; box-shadow: 0 2px 3px #999999;';
  30. container.appendChild(input);
  31. // bind keypress-enter event.
  32. input.addEventListener('keypress', function (evt) {
  33. if (evt.keyCode === 13) {
  34. var value = input.value.trim() || '';
  35. if (value !== '') {
  36. document.querySelector('#lst-ib').value = value;
  37. document.querySelector('.lsb').click();
  38. }
  39. }
  40. }, false);
  41. // create the goto-top button.
  42. var btn = document.createElement('div');
  43. btn.id = 'goto-top-btn';
  44. btn.innerHTML = 'TOP';
  45. btn.onclick = gotoTop;
  46. // set button CSS style.
  47. btn.style = 'display: inline-block; position: relative; left: -7px; color: #fff; line-height: 60px; text-align: center;' +
  48. 'width: 60px; height: 60px; background: #4285F4; box-shadow: 0 2px 3px #999999;' +
  49. 'cursor: pointer; font-weight: bolder; border-radius: 100%;';
  50. // append the go-to-top to search form to successfully attach to the UI.
  51. container.appendChild(btn);
  52. var form = document.querySelector('#searchform');
  53. form.appendChild(container);
  54. window.onload = function () {
  55. var doc = document.documentElement;
  56. var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
  57. if (top !== 0) {
  58. container.style.display = 'flex';
  59. }
  60. }
  61. // bind button hiden/show event.
  62.  
  63. window.onscroll = function () {
  64. var doc = document.documentElement;
  65. var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
  66. if (top === 0) {
  67. container.style.display = 'none';
  68. } else {
  69. container.style.display = 'flex';
  70. }
  71. }
  72. function gotoTop() {
  73. goto(Math.floor(window.pageYOffset / 5));
  74. }
  75. function goto(step) {
  76. setTimeout(function () {
  77. window.scrollTo(0, window.pageYOffset - step);
  78. if (window.pageYOffset <= 0) return;
  79. goto(step);
  80. }, 100);
  81. }
  82. }) (window, document, undefined);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址