// ==UserScript== // @name 🔄️ 下拉刷新 // @namespace https://ez118.github.io/ // @version 0.1.0 // @description 为Via设计的网页下拉手势刷新页面的功能 // @author ZZY_WISU // @match *://*/* // @grant GM_addStyle // @grant GM_addElement // @license MIT // @run-at document-end // @downloadURL https://update.greasyfork.icu/scripts/565329/%F0%9F%94%84%EF%B8%8F%20%E4%B8%8B%E6%8B%89%E5%88%B7%E6%96%B0.user.js // @updateURL https://update.greasyfork.icu/scripts/565329/%F0%9F%94%84%EF%B8%8F%20%E4%B8%8B%E6%8B%89%E5%88%B7%E6%96%B0.meta.js // ==/UserScript== (function() { 'use strict'; const maxDistance = 80; const container = document.querySelector('body'); // 禁用浏览器默认滚动行为 GM_addStyle(` html,body { overscroll-behavior: none; } @keyframes userscript_slide2load { from { transform: rotateZ(0deg); } to { transform: rotateZ(720deg); } } `); const loader = GM_addElement( container.parentNode, "div", { style: "position:fixed;top:-52px;left:calc(50% - 24px);z-index:10000000001;border:1px solid #888888;box-sizing:border-box!important;visibility:visible;display:flex;justify-content:center;align-items:center;width:48px;height:48px;padding:8px;border-radius:50%;opacity:0.75;background:#FFF;color:#000;font-size:25px;user-select:none;cursor:wait;", textContent: " ↻ " } ); let startY = 0, distance = 0; container.addEventListener('touchstart', e => { startY = e.touches[0].pageY; container.style.transition = 'transform 0s'; loader.style.transition = 'transform 0s'; }); container.addEventListener('touchmove', e => { distance = e.touches[0].pageY - startY; distance /= 5; if (distance > 0 && distance <= maxDistance) { container.style.transform = `translateY(${(distance)}px)`; loader.style.transform = `rotateZ(${(distance * 6)}deg)`; loader.style.top = `${(distance * 2)}px`; } }); container.addEventListener('touchend', () => { if (distance > maxDistance - 10) { setTimeout(() => window.location.reload(), 200); console.log("刷新数据中..."); loader.style.animation = "userscript_slide2load 1.5s linear infinite"; } else { loader.style.transition = 'transform 0.5s ease'; loader.style.transform = 'rotateZ(0deg)'; loader.style.top = `-52px`; } container.style.transition = 'transform 0.5s ease'; container.style.transform = 'translateY(0px)'; }); })();