// ==UserScript== // @name 回到顶部 // @namespace http://tampermonkey.net/ // @version 0.7 // @description 自动生成一个带有回到顶部功能的按钮 // @author CoderBen // @match *://*/* // @icon https://cdn3.iconfinder.com/data/icons/leto-space/64/__rocket_spaceship-64.png // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; if (window.frames.length === parent.frames.length) { createButton() } function createButton() { const btn = document.createElement('div') btn.innerHTML = '↑' btn.style.fontSize = '28px' btn.style.fontWeight = 900 btn.style.textAlign = 'center' btn.style.lineHeight = '50px' btn.style.cursor = 'pointer' btn.style.width = '50px' btn.style.height = '50px' btn.style.background = '#f7f7f7' btn.style.position = 'fixed' btn.style.right = '400px' btn.style.bottom = '50px' btn.onclick = () => scrollTo(0, 0) btn.oncontextmenu = (e) => { e.preventDefault() btn.style.display = 'none' } document.querySelector('html body').appendChild(btn) } })();