Scroll to Top

Adds a button on every page which scrolls to the top.

当前为 2024-03-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Scroll to Top
  3. // @namespace Marascripts
  4. // @description Adds a button on every page which scrolls to the top.
  5. // @author marascripts
  6. // @version 1.0.1
  7. // @grant none
  8. // @match https://www.marapets.com/*
  9. // @homepageURL https://github.com/marascript/userscripts
  10. // @supportURL https://github.com/marascript/userscripts/issues
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (() => {
  15. 'use strict'
  16.  
  17. const toTopButton = document.createElement('a')
  18. toTopButton.innerText = '⬆️'
  19. toTopButton.style.cursor = 'pointer'
  20. toTopButton.style.fontSize = '3em'
  21.  
  22. // Anchor to bottom of page
  23. toTopButton.style.position = 'fixed'
  24. toTopButton.style.bottom = '5%'
  25. toTopButton.style.right = '2%'
  26.  
  27. // Make button slightly opaque until hover
  28. toTopButton.style.opacity = 0.25
  29. toTopButton.onmouseenter = () => toTopButton.style.opacity = 1
  30. toTopButton.onmouseleave = () => toTopButton.style.opacity = 0.25
  31.  
  32. // Scroll to top, without modifying URL
  33. toTopButton.onclick = () => window.scrollTo(0, 0)
  34.  
  35. document.querySelector('body').appendChild(toTopButton)
  36. })()