// ==UserScript==
// @name 滚动条
// @namespace https://palhube666.wodemo.com
// @version 0.1
// @description 在每个页面右边添加一个滚动按钮
// @author MT浏览器
// @run-at document-start
// @match https://*/*
// @grant none
// ==/UserScript==
/*在每个页面右边添加一个滚动按钮*/
function createScrollBar() { var isScrollBar,startY,endY,whereScroll,clearScrollBar; var clientHeight = document.body.clientHeight; var scrollTop = document.documentElement.scrollTop; isScrollBar = document.getElementById('theScrollBar'); if (isScrollBar) { isScrollBar.parentNode.removeChild(isScrollBar); }; var theScrollBar = document.createElement("div"); theScrollBar.id = "theScrollBar"; theScrollBar.addEventListener("touchstart",function (e) { e.stopPropagation(); e.preventDefault(); if ( clearScrollBar ) { clearTimeout( clearScrollBar ); }; return startY = e.changedTouches[0].clientY - parseFloat(this.style.top); },true); theScrollBar.addEventListener("touchmove",function (e) { e.stopPropagation(); e.preventDefault(); if ( clearScrollBar ) { clearTimeout( clearScrollBar ); }; endY = e.changedTouches[0].clientY; var theTop = endY - startY; this.style.top = theTop + "px"; thePageTop = theTop / document.documentElement.clientHeight * document.body.clientHeight; document.body.scroll(0,thePageTop); },true); theScrollBar.addEventListener("touchend",function (e) { e.stopPropagation(); e.preventDefault(); var that = this; clearScrollBar = setTimeout(function () { if ( whereScroll ) { clearInterval(whereScroll); }; that.style.display = "none"; },3000); return clearScrollBar; },true); theScrollBar.innerHTML = "△<br>▽"; theScrollBar.setAttribute("style","font-size:4vw !important;width:8vw !important;line-height:8vw !important;text-align:center !important;background-color:rgba(255,255,255,0.7) !important;box-shadow:0px 1px 5px rgba(0,0,0,0.2) !important;color:#000 !important;position:fixed !important;top:" + scrollTop + "px;right:0 !important;z-index:999999 !important;border-radius:1vw !important;display:block"); document.body.appendChild(theScrollBar); document.ontouchmove = function () { if ( clearScrollBar ) { clearTimeout( clearScrollBar ); }; var scrollBar = document.getElementById('theScrollBar'); scrollBar.style.display = "block"; if ( !whereScroll ) { whereScroll = setInterval(function () { var nowScrollTop = document.body.scrollTop; var theTop = ( nowScrollTop/document.body.clientHeight ) * document.documentElement.clientHeight; scrollBar.style.top = theTop + "px"; },1); return whereScroll; }; }; document.ontouchstart = function () { if ( whereScroll ) { clearInterval(whereScroll); }; whereScroll = setInterval(function () { var scrollBar = document.getElementById('theScrollBar'); var nowScrollTop = document.body.scrollTop; var theTop = ( nowScrollTop/document.body.clientHeight ) * document.documentElement.clientHeight; scrollBar.style.top = theTop + "px"; },1); return whereScroll; }; document.ontouchend = function () { var scrollBar = document.getElementById('theScrollBar'); clearScrollBar = setTimeout(function () { scrollBar.style.display = "none"; if ( whereScroll ) { clearInterval(whereScroll); }; },3000); return clearScrollBar; }; }; createScrollBar();
Back to home |
File page
Subscribe |
Register |
Login
| N