您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
解放双手!点击直接返回页面顶部,再也不用一点一点往上滑啦!
当前为
// ==UserScript== // @name 妖火回顶部 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 解放双手!点击直接返回页面顶部,再也不用一点一点往上滑啦! // @license MIT // @author cradms // @match *://yaohuo.me/bbs* // @match *://www.yaohuo.me/bbs* // @icon https://www.google.com/s2/favicons?sz=64&domain=yaohuo.me // @grant none // ==/UserScript== (function() { const svg = ` <svg width="24" height="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M24.0083 14.1006V42.0001" stroke="#eee" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/> <path d="M12 26L24 14L36 26" stroke="#eee" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/> <path d="M12 6H36" stroke="#eee" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/> </svg>`; const dom = document.createElement('div'); dom.innerHTML = svg; Object.assign(dom.style, { position: 'fixed', right: '20px', bottom: '20px', width: '40px', height: '40px', backgroundColor: '#4595d5', borderRadius: '4px', fontSize: '15px', textAlign: 'center', lineHeight: '40px', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', visibility: 'hidden' }); document.body.appendChild(dom); function scrollToTop({ el, speed = 5, top = 0, distance = 300 }) { window.addEventListener('scroll', () => { el.style.visibility = (document.documentElement.scrollTop || document.body.scrollTop) > distance ? 'visible' : 'hidden'; }); el.addEventListener('click', () => { const scrollStep = () => { const currentScroll = document.documentElement.scrollTop || document.body.scrollTop; if (currentScroll > top) { window.requestAnimationFrame(scrollStep); window.scrollTo(0, currentScroll - (currentScroll / speed)); } }; scrollStep(); }); } scrollToTop({ el: dom }); })();