Github返回页顶按钮

给github的每个页面添加一个返回页顶的按钮。

  1. // ==UserScript==
  2. // @name Github To The Top Button
  3. // @name:zh-CN Github返回页顶按钮
  4. // @namespace https://github.com/
  5. // @version 0.1
  6. // @description Add a to-the-top button into the github's pages.
  7. // @description:zh-CN 给github的每个页面添加一个返回页顶的按钮。
  8. // @author ETY001
  9. // @match https://github.com/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var topbtn = document.createElement("div");
  16. topbtn.innerHTML = '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1498751358770" class="icon" style="" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2557" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M21.490332 682.20038c0-15.021112 5.711312-30.036084 17.169752-41.500183l430.195516-430.17746c22.882087-22.915919 60.038871-22.915919 82.956775 0l430.238496 430.17746c22.916881 22.922059 22.916881 60.036351 0 82.95841-22.882087 22.915919-60.038871 22.915919-82.955752 0L510.351385 334.975191 121.65677 723.659631c-22.923021 22.915919-60.038871 22.915919-82.961892 0C27.20062 712.236464 21.490332 697.215352 21.490332 682.20038L21.490332 682.20038zM21.490332 682.20038" p-id="2558"></path></svg>';
  17. topbtn.style = 'position: fixed; bottom: 50px; right: 10%; background-color: #ddd; padding: 10px; border-radius: 15px; cursor: pointer;';
  18. topbtn.firstElementChild.style = 'width: 40px; height:40px;';
  19. document.getElementsByTagName('body')[0].appendChild(topbtn);
  20. window.onscroll = function(){
  21. var top = document.documentElement.scrollTop || document.body.scrollTop;
  22. if( top >= 300 ) {
  23. topbtn.style.bottom=50+'px';
  24. } else {
  25. topbtn.style.bottom=-1000+'px';
  26. }
  27. };
  28. var intervalTimer = null;
  29. topbtn.onclick = function(){
  30. intervalTimer=setInterval(function(){
  31. var top = document.documentElement.scrollTop || document.body.scrollTop;
  32. top-=1000;
  33. if (top>0) {
  34. window.scrollTo(0,top);
  35. } else {
  36. window.scrollTo(0,0);
  37. clearInterval(intervalTimer);
  38. }
  39. } , 1);
  40. };
  41. })();

QingJ © 2025

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