// ==UserScript== // ==UserScript== // @name 边缘下滑刷新 // @namespace https://greasyfork.org/zh-CN/users/954189 // @version 2.1 // @description 山寨自神奇浏览器,效果一般,将就用。 // @author angao // @license MIT // @match https://*/* // @downloadURL none // ==/UserScript== let startY = null; let endY = null; let mark = 0; //注入CSS var style = document.createElement('style'); style.innerHTML = ` .Refresh_Icon { width: 42px; height: 42px; border-radius: 8px; position: fixed; left: 50%; transform: translate(-50%,0); box-shadow: 0 3px 6px rgb(0 0 0 / 16%), 0 1px 2px rgb(0 0 0 / 23%); top: -42px; display: 'flex'; align-items: center; justify-content: center; z-index: 99999999; background-color: white; border-radius: 50%; } .Refresh_Icon svg { width: 24px; height: 24px; margin: 0; } `; document.head.appendChild(style); // 创建DOM绑定方法 const Icon = document.createElement('div') Icon.className = 'Refresh_Icon' Icon.innerHTML =` `; //默认显示 Icon.style.display = 'flex' document.body.appendChild(Icon) //记录触摸点的纵坐标 document.addEventListener('touchstart', function(e) { if (e.touches[0].clientX < 30 || e.touches[0].clientX > window.innerWidth - 30) { startY = e.touches[0].clientY; mark = 1; } }); let maxDistance = 100; // 最大下滑距离 let slowDownStart = 70; // 开始减速的位置 let slowDownRate = 0.3; // 减速比率 //阻止屏幕滑动 document.addEventListener('touchmove', function(e) { if (mark) { e.preventDefault(); } if (startY !== null) { let distance = e.touches[0].clientY - startY; if (distance > slowDownStart) { distance = slowDownStart + (distance - slowDownStart) * slowDownRate; } distance = Math.min(distance, maxDistance); Icon.style.transform = `translate(-50%, ${distance}px) rotate(${distance * 5}deg)`; } }, { passive: false }); //记录离开点的纵坐标 document.addEventListener('touchend', function(e) { if (startY !== null ) { endY = e.changedTouches[0].clientY; // 向下滑动超过120像素则刷新 if (endY - startY > 120) { location.reload(); } } Icon.style.transition = 'all 0.5s'; Icon.style.transform = 'translate(-50%, -42px) rotate(-360deg)'; setTimeout(() => { Icon.style.transition = ''; }, 500); startY = null; endY = null; mark = 0; });