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.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Pixel-Precision Wheel Scroll
// @namespace    https://greasyfork.org/en/users/85671-jcunews
// @version      1.0.3
// @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.
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

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.stopPropagation();
      ev.preventDefault()
    } else if (ev.altKey && !ev.shiftKey) {
      ele.scrollBy(ev.deltaY > 0 ? 1 : -1, 0);;
      ev.stopPropagation();
      ev.preventDefault()
    }
  }
}, {capture: true, passive: false})