Github一键返回顶部

Github返回顶部

스크립트 설치?
개발자의 추천 스크립트

为网站添加一键返回顶部는 어떤가요?

스크립트 설치
질문, 리뷰하거나, 이 스크립트를 신고하세요.
  1. // ==UserScript==
  2. // @name Github一键返回顶部
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Github返回顶部
  6. // @author GM
  7. // @match https://github.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. let css=`
  14. .goup {
  15. cursor: pointer;
  16. top: 75vh;
  17. position: fixed;
  18. right: 1vw;
  19. font-family: 'Open Sans', sans-serif;
  20. padding: 0;
  21. font-size: inherit;
  22. color: inherit;
  23. box-sizing: inherit;
  24. backface-visibility: hidden;
  25. -webkit-font-smoothing: antialiased;
  26. text-decoration: none;
  27. transition: all 0.35s;
  28. transition-timing-function: cubic-bezier(0.31, -0.105, 0.43, 1.59);
  29. display: inline-block;
  30. background-color: #fff;
  31. width: 90px;
  32. height: 90px;
  33. line-height: 90px;
  34. margin: 0 10px;
  35. text-align: center;
  36. overflow: hidden;
  37. border-radius: 28%;
  38. box-shadow: 0 5px 15px -5px rgba(0,0,0,0.45);
  39. opacity: 0.99;
  40. background-position: center;
  41. background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAABYNJREFUeF7tncmuW0UQhv+W7yMgJJQ1m2TBgnkmzPOc7HgE1NWyxA6xYMXiysd5CpQwQxjCPENgA9KNxAuEBQ/AymrkKFfA1Y1d7T62T3X9Xledc/7//7rO4CmAL9cOBNfqKR4EwDkEBIAAOHfAuXxOAALg3AHn8jkBCIBzB5zL5wQgAM4dcC6fE4AAOHfAuXxOAALg3AHn8jkBCIBzB5zL5wQgAM4dcC6fE4AAOHfAuXxOAALg3AHn8jkBCIBzB5zL5wQgAM4dcC6fE4AAOHfAuXxOAALg3AHn8jkBCIBzB5zL5wQgAM4dcC6fE4AA+HNARF4B8AK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bOvpQCIyPwPluZ/tLToxfA1bvdQo4Gg5DSgAeAaABcXHDvD7yHYkk0sgiCEcGYymZzUbm8pAPMNLfjiJsPXOt1z3WUIugPfr7jYdd2Rkl2pALgMwSkAL+5vPOf8+s7OzqslV5wlB8ZanQMxxhMhhKM55wvT6XR+m170UgMw32pK6UjO+VoAf3Rd92fRnlg8SAeKABikAh5UlQMEoMo++80EwH6GVQoIQJV99psJgP0MqxQQgCr77DcTAPsZVikgAFX22W8mAPYzrFJAAKrss99MAOxnWKWAAFTZZ7+ZANjPsEoBAaiyz34zAbCfYZUCAlBln/1mAmA/wyoFBKDKPvvNBMB+hlUKCECVffabCYD9DKsUEIAq++w3EwD7GVYpIABV9tlvJgD2M6xSQACq7LPfTADsZ1ilgABU2We/mQDYz7BKAQGoss9+MwGwn2GVAgJQZZ/9ZgJgP8MqBf8Aq+r9n3aJFIMAAAAASUVORK5CYII=');
  42. background-repeat: no-repeat;
  43. background-size: 50%;
  44. }
  45. .goup:hover{
  46. background-size: 80%;
  47. }
  48. `;
  49. document.getElementsByTagName('style')[0].textContent+=document.getElementsByTagName('style')[0].textContent+css; // 第一个style内容
  50. let body = document.querySelector('body');
  51. let a=document.createElement('i');
  52. a.className='goup';
  53. a.style.display='none'
  54. body.appendChild(a);
  55. let now =document.documentElement.scrollTop||document.body.scrollTop;
  56. if(now>window.innerHeight){
  57. a.style.display='block';
  58. }
  59. a.onclick=function(){
  60. window.scrollTo({
  61. top: 0,
  62. behavior: 'smooth',
  63. });
  64. return false;
  65. }
  66. window.onscroll=function(){
  67. let t =document.documentElement.scrollTop||document.body.scrollTop; //变量t就是滚动条滚动时,到顶部的距离
  68. if(t>window.innerHeight){
  69. //滚动到完一页后显示回到顶部
  70. a.style.display='block';
  71. }else{
  72. a.style.display='none';
  73. }
  74. }
  75. // Your code here...
  76. })();