Greasy Fork镜像 还支持 简体中文。

Quick search & Go to Top -- Google

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

目前為 2015-09-06 提交的版本,檢視 最新版本

  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
  8. // @grant none
  9. // ==/UserScript==
  10. (function (window, document, undefined) {
  11. var container = document.createElement('div');
  12. container.style = 'display: none; position: fixed; bottom: 10px;' +
  13. 'right: 10px; text-align: right;' +
  14. 'width: 260px; height: 40px; background: #343C45; z-index: 999999999;' +
  15. 'opacity: 0.8;';
  16.  
  17. // create quick query input.
  18. var input = document.createElement('input');
  19. input.tyle = 'text';
  20. input.value = document.querySelector('#lst-ib').value;
  21. input.setAttribute('placeholder', 'Search...');
  22. input.style = 'border: none; border-left: solid #EA4335 5px; flex: 1; display: inline-block; outline: none; height: 40px;' +
  23. 'font-size: 15px; padding: 0; padding-left: 10px; padding-right: 10px; background: #D9D9D9;';
  24. container.appendChild(input);
  25. // bind keypress-enter event.
  26. input.addEventListener('keypress', function (evt) {
  27. if (evt.keyCode === 13) {
  28. var value = input.value.trim() || '';
  29. if (value !== '') {
  30. document.querySelector('#lst-ib').value = value;
  31. document.querySelector('.lsb').click();
  32. }
  33. }
  34. }, false);
  35. // create the goto-top button.
  36. var btn = document.createElement('div');
  37. btn.id = 'goto-top-btn';
  38. btn.innerHTML = 'TOP';
  39. btn.onclick = gotoTop;
  40. // set button CSS style.
  41. btn.style = 'display: inline-block; color: #fff; line-height: 42px; text-align: center;' +
  42. 'width: 40px; height: 40px; background: #4285F4;' +
  43. 'cursor: pointer; font-weight: bolder;';
  44. // append the go-to-top to search form to successfully attach to the UI.
  45. container.appendChild(btn);
  46. var form = document.querySelector('#searchform');
  47. form.appendChild(container);
  48. window.onload = function () {
  49. var doc = document.documentElement;
  50. var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
  51. if (top !== 0) {
  52. container.style.display = 'flex';
  53. }
  54. }
  55. // bind button hiden/show event.
  56. window.onscroll = function() {
  57. var doc = document.documentElement;
  58. var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
  59. if (top === 0) {
  60. container.style.display = 'none';
  61. } else {
  62. container.style.display = 'flex';
  63. }
  64. }
  65. function gotoTop() {
  66. goto(Math.floor(window.pageYOffset / 5));
  67. }
  68. function goto(step) {
  69. setTimeout(function () {
  70. window.scrollTo(0, window.pageYOffset - step);
  71. if (window.pageYOffset <= 0) return;
  72. goto(step);
  73. }, 100);
  74. }
  75. })(window, document, undefined);

QingJ © 2025

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