// ==UserScript== // @name Github To The Top Button // @name:zh-CN Github返回页顶按钮 // @namespace https://github.com/ // @version 0.1 // @description Add a to-the-top button into the github's pages. // @description:zh-CN 给github的每个页面添加一个返回页顶的按钮。 // @author ETY001 // @match https://github.com/* // @grant none // @downloadURL https://update.greasyfork.icu/scripts/31017/Github%20To%20The%20Top%20Button.user.js // @updateURL https://update.greasyfork.icu/scripts/31017/Github%20To%20The%20Top%20Button.meta.js // ==/UserScript== (function() { 'use strict'; var topbtn = document.createElement("div"); topbtn.innerHTML = ''; topbtn.style = 'position: fixed; bottom: 50px; right: 10%; background-color: #ddd; padding: 10px; border-radius: 15px; cursor: pointer;'; topbtn.firstElementChild.style = 'width: 40px; height:40px;'; document.getElementsByTagName('body')[0].appendChild(topbtn); window.onscroll = function(){ var top = document.documentElement.scrollTop || document.body.scrollTop; if( top >= 300 ) { topbtn.style.bottom=50+'px'; } else { topbtn.style.bottom=-1000+'px'; } }; var intervalTimer = null; topbtn.onclick = function(){ intervalTimer=setInterval(function(){ var top = document.documentElement.scrollTop || document.body.scrollTop; top-=1000; if (top>0) { window.scrollTo(0,top); } else { window.scrollTo(0,0); clearInterval(intervalTimer); } } , 1); }; })();