Scroll to Bottom

Add a button to scroll to the bottom of the websit

当前为 2023-11-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Scroll to Bottom
  3. // @name:zh 底部按钮
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.1
  6. // @description Add a button to scroll to the bottom of the websit
  7. // @description:zh 添加一个按钮滚动到网站底部
  8. // @author You
  9. // @match *://*/*
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Base64-encoded SVG data
  18. const base64Icon = 'PHN2ZyBzdHJva2U9ImN1cnJlbnRDb2xvciIgZmlsbD0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIyIiB2aWV3Qm94PSIwIDAgMjQgMjQiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgY2xhc3M9Imljb24tc20gbS0xIiBoZWlnaHQ9IjFlbSIgd2lkdGg9IjFlbSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48bGluZSB4MT0iMTIiIHkxPSI1IiB4Mj0iMTIiIHkyPSIxOSI+PC9saW5lPjxwb2x5bGluZSBwb2ludHM9IjE5IDEyIDEyIDE5IDUgMTIiPjwvcG9seWxpbmU+PC9zdmc+';
  19.  
  20. // Create the button
  21. const button = document.createElement('button');
  22. button.innerHTML = `<img src="data:image/svg+xml;base64,${base64Icon}" alt="Scroll to Bottom">`;
  23.  
  24. // Apply styles to the button
  25. button.style.position = 'fixed';
  26. button.style.bottom = '16px';
  27. button.style.right = '16px';
  28. button.style.zIndex = '9999';
  29. button.style.backgroundColor = 'none';
  30. button.style.border = '1px solid none';
  31. button.style.borderRadius = '50%';
  32. button.style.padding = '4px';
  33. button.style.cursor = 'pointer';
  34.  
  35. // Add click event listener to scroll to the bottom
  36. button.addEventListener('click', function() {
  37. window.scrollTo({
  38. top: document.body.scrollHeight,
  39. behavior: 'smooth'
  40. });
  41. });
  42.  
  43. // Append the button to the body
  44. document.body.appendChild(button);
  45. })();