边缘下滑刷新.改

在屏幕左右边缘下滑时刷新网页

  1. // ==UserScript==
  2. // @name 边缘下滑刷新.改
  3. // @version 1.8
  4. // @description 在屏幕左右边缘下滑时刷新网页
  5. // @author angao
  6. // @run-at document-end
  7. // @license MIT
  8. // @match *://*/*
  9. // @namespace https://gf.qytechs.cn/users/452911
  10. // ==/UserScript==
  11.  
  12. (function EdgeSlideRefresh() {
  13. 'use strict';
  14.  
  15. // 设置刷新图标大小
  16. const setRefreshIconSize = () => {
  17. if (window.innerWidth < window.innerHeight) {
  18. document.querySelector('.Refresh_Icon').style.width = `calc(100vw / 11)`;
  19. document.querySelector('.Refresh_Icon').style.height = `calc(100vw / 11)`;
  20. } else {
  21. document.querySelector('.Refresh_Icon').style.width = `calc(100vh / 5)`;
  22. document.querySelector('.Refresh_Icon').style.height = `calc(100vh / 5)`;
  23. }
  24. }
  25.  
  26. // 设置滑动刷新的距离阈值
  27. const Sliderefreshdistance = window.innerHeight * (window.innerWidth < window.innerHeight ? 1 / 4 : 2 / 3);
  28. let startY = null;
  29. let endY = null;
  30.  
  31. // 创建样式
  32. var style = document.createElement('style');
  33. style.innerHTML = `.Refresh_Icon { border-radius: 50%; position: fixed; left: 50%; transform: translate(-50%, 0) translateZ(0); box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); top: -${100 / 11}vw; align-items: center; justify-content: center; z-index: 99999999; background-color: white; transition: transform 0.05s ease-out; } .Refresh_Icon svg { width: calc(70% * 100vw / 11); height: calc(70% * 100vw / 11); margin: 0; }`;
  34. document.head.appendChild(style);
  35.  
  36. // 创建刷新图标元素
  37. const Icon = document.createElement('div');
  38. Icon.className = 'Refresh_Icon';
  39. Icon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/></svg>`;
  40.  
  41. Icon.style.display = 'none';
  42. document.body.appendChild(Icon);
  43.  
  44. setRefreshIconSize();
  45.  
  46. window.addEventListener('resize', setRefreshIconSize);
  47.  
  48. // 触摸开始事件监听
  49. document.addEventListener('touchstart', function(e) {
  50. if (e.touches[0].clientX < window.innerWidth / 18 || e.touches[0].clientX > window.innerWidth * 17 / 18) {
  51. startY = e.touches[0].clientY;
  52. Icon.style.display = 'flex';
  53. }
  54. });
  55.  
  56. // 触摸移动事件监听
  57. document.addEventListener('touchmove', function(e) {
  58. if (startY !== null && (e.touches[0].clientX < window.innerWidth / 18 || e.touches[0].clientX > window.innerWidth * 17 / 18)) {
  59. e.preventDefault();
  60. let distance = e.touches[0].clientY - startY;
  61. let slowDownStart = Sliderefreshdistance * 0.6;
  62. let slowDownRate = 0.2;
  63. if (distance < Sliderefreshdistance) {
  64. Icon.querySelector('svg').style.fill = 'black';
  65. } else {
  66. Icon.querySelector('svg').style.fill = 'darkred';
  67. }
  68. if (distance > slowDownStart) {
  69. distance = slowDownStart + (distance - slowDownStart) * slowDownRate;
  70. }
  71. distance = Math.min(distance, Sliderefreshdistance * 0.85);
  72. Icon.style.transform = `translate(-50%, ${distance / 1.35}px) rotate(${distance * 2}deg)`;
  73. }
  74. }, { passive: false });
  75.  
  76. // 触摸结束事件监听
  77. document.addEventListener('touchend', function(e) {
  78. if (startY !== null && (e.changedTouches[0].clientX < window.innerWidth / 18 || e.changedTouches[0].clientX > window.innerWidth * 17 / 18)) {
  79. endY = e.changedTouches[0].clientY;
  80. if (endY - startY > Sliderefreshdistance) {
  81. setTimeout(function() {
  82. location.reload();
  83. }, 250);
  84. }
  85. Icon.style.transition = 'all 0.5s';
  86. Icon.style.transform = 'translate(-50%, -42px)';
  87. setTimeout(() => {
  88. Icon.style.transition = '';
  89. Icon.style.display = 'none';
  90. }, 500);
  91. startY = null;
  92. endY = null;
  93. }
  94. });
  95. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址