// ==UserScript== // @name 通用网页置顶/置底工具(Universal webpage sticky tool) // @namespace http://tampermonkey.net/ // @version 1.1 // @description 高端毛玻璃UI + 暴力探测滚动逻辑,去除平滑滚动动画实现瞬间跳转,完美兼容 Gemini 等严格单页应用。 // @author Max Linker with Gemini Pro // @match *://*/* // @icon https://www.google.com/s2/favicons?sz=64&domain=gemini.google.com // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/568986/%E9%80%9A%E7%94%A8%E7%BD%91%E9%A1%B5%E7%BD%AE%E9%A1%B6%E7%BD%AE%E5%BA%95%E5%B7%A5%E5%85%B7%28Universal%20webpage%20sticky%20tool%29.user.js // @updateURL https://update.greasyfork.icu/scripts/568986/%E9%80%9A%E7%94%A8%E7%BD%91%E9%A1%B5%E7%BD%AE%E9%A1%B6%E7%BD%AE%E5%BA%95%E5%B7%A5%E5%85%B7%28Universal%20webpage%20sticky%20tool%29.meta.js // ==/UserScript== (function() { 'use strict'; // 1. 创建毛玻璃按钮容器 const container = document.createElement('div'); container.style.cssText = ` position: fixed; bottom: 50px; right: 30px; display: flex; flex-direction: column; gap: 12px; z-index: 2147483647; opacity: 0.4; transition: opacity 0.4s ease; `; container.onmouseover = () => container.style.opacity = '1'; container.onmouseleave = () => container.style.opacity = '0.4'; // 2. 使用原生 DOM API 安全创建 SVG 图标 const createSvgIcon = (points) => { const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); svg.setAttribute("viewBox", "0 0 24 24"); svg.setAttribute("width", "20"); svg.setAttribute("height", "20"); svg.setAttribute("stroke", "#444444"); svg.setAttribute("stroke-width", "2"); svg.setAttribute("fill", "none"); svg.setAttribute("stroke-linecap", "round"); svg.setAttribute("stroke-linejoin", "round"); const polyline = document.createElementNS("http://www.w3.org/2000/svg", "polyline"); polyline.setAttribute("points", points); svg.appendChild(polyline); return svg; }; // 3. 创建高定质感按钮 const createBtn = (iconElement, title, onClick) => { const btn = document.createElement('button'); btn.appendChild(iconElement); btn.title = title; btn.style.cssText = ` width: 46px; height: 46px; padding: 0; display: flex; justify-content: center; align-items: center; background: rgba(255, 255, 255, 0.65); border: 1px solid rgba(255, 255, 255, 0.8); border-radius: 50%; cursor: pointer; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); `; btn.onmouseover = () => { btn.style.transform = 'translateY(-3px)'; btn.style.background = 'rgba(255, 255, 255, 0.95)'; btn.style.boxShadow = '0 8px 20px rgba(0, 0, 0, 0.12)'; }; btn.onmouseleave = () => { btn.style.transform = 'translateY(0)'; btn.style.background = 'rgba(255, 255, 255, 0.65)'; btn.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.08)'; }; btn.onclick = onClick; return btn; }; // 4. 暴力滚动逻辑(瞬间跳转) const doScroll = (isTop) => { // 移除了 behavior: 'smooth',默认即为瞬间跳转 const scrollOptions = { top: isTop ? 0 : 9999999 }; // 第一步:全局滚动 window.scrollTo(scrollOptions); document.documentElement.scrollTo(scrollOptions); document.body.scrollTo(scrollOptions); // 第二步:内部容器暴力探测滚动 const elements = document.querySelectorAll('*'); for (let el of elements) { if (el.scrollHeight > el.clientHeight && el.clientHeight > 0) { const overflowY = window.getComputedStyle(el).overflowY; if (overflowY === 'auto' || overflowY === 'scroll' || overflowY === 'overlay') { // 同样移除平滑过渡,实现秒切 el.scrollTo({ top: isTop ? 0 : el.scrollHeight }); } } } }; // 5. 生成图标并挂载到页面 container.appendChild(createBtn(createSvgIcon("18 15 12 9 6 15"), '一键置顶', () => doScroll(true))); container.appendChild(createBtn(createSvgIcon("6 9 12 15 18 9"), '一键置底', () => doScroll(false))); // 延迟挂载,避开 SPA 初始化清理 setTimeout(() => { document.body.appendChild(container); }, 1000); })();