🐋 潜入海底,浮出水面

当前为 2022-12-24 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         鲸
// @namespace    https://github.com/mefengl
// @version      0.0.1
// @description  🐋 潜入海底,浮出水面
// @author       mefengl
// @match        http://*/*
// @match        https://*/*
// @exclude      https://www.baidu.com/
// @icon         none
// @require      https://cdn.staticfile.org/jquery/3.6.1/jquery.min.js
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  "use strict";
  $(function () {
    // if page's height is less than 1000px, then return
    if (document.body.scrollHeight < 1000) return;

    // if page's height is less than 2000px, then make button less visible
    const hide_right = document.body.scrollHeight < 3000 ? "-130px" : "-120px";

    // create the button
    $("<button>深潜</button>")
      .click(function () {
        // scroll to the bottom of the page, if already at the bottom, then scroll to the top
        if (document.body.scrollHeight - window.innerHeight - window.scrollY < 100) {
          window.scrollTo({ top: 0, behavior: "smooth" });
          $(this).text("深潜").css({ "background-color": "#0d47a1", color: "#fff" });
        } else {
          window.scrollTo({ top: document.body.scrollHeight, behavior: "smooth" });
          $(this).text("浮出").css({ "background-color": "#e0e0e0", color: "#000", border: "1px solid #a0a0a0" });
        }
      })
      .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", })
      .hover(
        // hover to show, and hide when not hover
        function () { $(this).stop().animate({ right: "-10px", }, 400); },
        function () { $(this).stop().animate({ right: hide_right, }, 400); }
      )
      .appendTo("body");
  });
})();