Pixel-Precision Wheel Scroll

Add pixel-precision wheel scrolling capability using CTRL+SHIFT+Wheel for vertical scroll, and CTRL+ALT+Wheel for horizontal scroll, for any scrollable element which can be scrolled at pixel level; as long as site script does not monopolize the wheel functionality.

目前為 2022-10-25 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Pixel-Precision Wheel Scroll
// @namespace    https://gf.qytechs.cn/en/users/85671-jcunews
// @version      1.0.2
// @license      AGPL v3
// @author       jcunews
// @description  Add pixel-precision wheel scrolling capability using CTRL+SHIFT+Wheel for vertical scroll, and CTRL+ALT+Wheel for horizontal scroll, for any scrollable element which can be scrolled at pixel level; as long as site script does not monopolize the wheel functionality.
// @match        *://*/*
// @grant        none
// ==/UserScript==

setTimeout(() => {
  addEventListener("wheel", (ev, ele) => {
    if (ev.ctrlKey) {
      ele = ev.target;
      while (ele && (ele.offsetWidth === ele.scrollWidth) && (ele.offsetHeight === ele.scrollHeight)) ele = ele.parentNode;
      ele = ele || window;
      if (ev.shiftKey && !ev.altKey) {
        ele.scrollBy(0, ev.deltaY > 0 ? 1 : -1);
        ev.preventDefault()
      } else if (ev.altKey && !ev.shiftKey) {
        ele.scrollBy(ev.deltaY > 0 ? 1 : -1, 0);;
        ev.preventDefault()
      }
    }
  }, {passive: false})
}, 20)

QingJ © 2025

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