mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
excmds.ts: Fix scrollpx not working on some websites
This commit is contained in:
parent
e122caa326
commit
ec6226b1e4
1 changed files with 24 additions and 2 deletions
|
@ -203,7 +203,10 @@ export function unfocus() {
|
||||||
|
|
||||||
//#content
|
//#content
|
||||||
export function scrollpx(a: number, b: number) {
|
export function scrollpx(a: number, b: number) {
|
||||||
window.scrollBy(a, b)
|
let top = document.body.getClientRects()[0].top;
|
||||||
|
window.scrollBy(a, b);
|
||||||
|
if (top == document.body.getClientRects()[0].top)
|
||||||
|
recursiveScroll(a, b, [document.body])
|
||||||
}
|
}
|
||||||
|
|
||||||
/** If two numbers are given, treat as x and y values to give to window.scrollTo
|
/** If two numbers are given, treat as x and y values to give to window.scrollTo
|
||||||
|
@ -227,13 +230,32 @@ export function scrollto(a: number, b: number | "x" | "y" = "y") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#content_helper
|
||||||
|
function recursiveScroll(x: number, y: number, nodes: Element[]) {
|
||||||
|
let rect = null;
|
||||||
|
let node = null;
|
||||||
|
do {
|
||||||
|
node = nodes.splice(0, 1)[0]
|
||||||
|
if (!node)
|
||||||
|
return
|
||||||
|
rect = node.getClientRects()[0]
|
||||||
|
} while (!rect)
|
||||||
|
let top = rect.top
|
||||||
|
node.scrollBy(x, y);
|
||||||
|
if (top == node.getClientRects()[0].top) {
|
||||||
|
let children = Array.prototype.slice.call(node.children).filter(DOM.isVisible)
|
||||||
|
recursiveScroll(x, y, nodes.concat(children))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//#content
|
//#content
|
||||||
export function scrollline(n = 1) {
|
export function scrollline(n = 1) {
|
||||||
window.scrollByLines(n)
|
window.scrollByLines(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
//#content
|
//#content
|
||||||
export function scrollpage(n = 1) {
|
export function scrollpage(n = 1) {
|
||||||
window.scrollBy(0, window.innerHeight * n)
|
scrollpx(0, window.innerHeight * n)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hidden */
|
/** @hidden */
|
||||||
|
|
Loading…
Add table
Reference in a new issue