-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHorizontal to Vertical Scroll Remapper.user.js
More file actions
51 lines (45 loc) · 1.48 KB
/
Copy pathHorizontal to Vertical Scroll Remapper.user.js
File metadata and controls
51 lines (45 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// ==UserScript==
// @name Horizontal to Vertical Scroll Remapper
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Redirect horizontal scroll (e.g., MX Master thumb wheel) to vertical scroll
// @author Abdul Khan
// @match *://*/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
function findScrollableParent(el) {
while (el && el !== document.body) {
const style = getComputedStyle(el);
const overflowY = style.overflowY;
if (
(overflowY === 'auto' || overflowY === 'scroll') &&
el.scrollHeight > el.clientHeight
) {
return el;
}
el = el.parentElement;
}
return null;
}
window.addEventListener("wheel", function (e) {
if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) {
const target = document.elementFromPoint(e.clientX, e.clientY);
if (!target) return;
let scrollable = findScrollableParent(target);
if (scrollable) {
e.preventDefault();
scrollable.scrollTop += e.deltaX;
} else {
// Fallback to scrolling the page
e.preventDefault();
window.scrollBy({
top: e.deltaX,
left: 0,
behavior: "auto"
});
}
}
}, { passive: false });
})();