🐋 潜入海底,浮出水面

  1. // ==UserScript==
  2. // @name 鲸
  3. // @namespace https://github.com/mefengl
  4. // @version 0.0.4
  5. // @description 🐋 潜入海底,浮出水面
  6. // @author mefengl
  7. // @match http://*/*
  8. // @match https://*/*
  9. // @exclude https://www.baidu.com/
  10. // @icon none
  11. // @require https://cdn.staticfile.org/jquery/3.6.1/jquery.min.js
  12. // @grant none
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. "use strict";
  18. $(function () {
  19. // if page's height is less than 1000px, then return
  20. if (document.body.scrollHeight < 1000) return;
  21.  
  22. // if page's height is less than 2000px, then make button less visible
  23. const hide_right = document.body.scrollHeight < 3000 ? "-130px" : "-120px";
  24.  
  25. // create the button
  26. $("<button>深潜</button>")
  27. .click(function () {
  28. // scroll to the bottom of the page, if already at the bottom, then scroll to the top
  29. if (document.body.scrollHeight - window.innerHeight - window.scrollY < 100) {
  30. window.scrollTo({ top: 0, behavior: "smooth" });
  31. $(this).text("深潜").css({ "background-color": "#0d47a1", color: "#fff" });
  32. } else {
  33. window.scrollTo({ top: document.body.scrollHeight, behavior: "smooth" });
  34. $(this).text("浮出").css({ "background-color": "#e0e0e0", color: "#000", border: "1px solid #a0a0a0" });
  35. }
  36. })
  37. .css({ "background-color": "#0d47a1", color: "#fff", position: "fixed", width: "140px", top: "220px", right: hide_right, "z-index": "999999", opacity: "0.8", border: "none", "border-radius": "4px", padding: "10px 16px", "font-size": "18px", cursor: "pointer", })
  38. .hover(
  39. // hover to show, and hide when not hover
  40. function () { $(this).stop().animate({ right: "-10px", }, 400); },
  41. function () { $(this).stop().animate({ right: hide_right, }, 400); }
  42. )
  43. .appendTo("body");
  44.  
  45. // hide button if full screen
  46. $(document).on("fullscreenchange", function () {
  47. document.fullscreenElement ? $button.hide() : $button.show();
  48. });
  49. });
  50. })();