rebasing
This commit is contained in:
26
runner/js/scroll.js
Normal file
26
runner/js/scroll.js
Normal file
@@ -0,0 +1,26 @@
|
||||
async (limit,timeout) => {
|
||||
const getScrollHeight = (element) => {
|
||||
if (!element) return 0
|
||||
|
||||
const { scrollHeight, offsetHeight, clientHeight } = element
|
||||
return Math.max(scrollHeight, offsetHeight, clientHeight)
|
||||
}
|
||||
|
||||
const position = await new Promise((resolve) => {
|
||||
let count = 0
|
||||
let limit_counter = 0
|
||||
const intervalId = setInterval(() => {
|
||||
const { body } = document
|
||||
const availableScrollHeight = getScrollHeight(body)
|
||||
|
||||
window.scrollBy(0, 250)
|
||||
count += 250
|
||||
limit_counter += 1
|
||||
if (count >= availableScrollHeight || limit_counter > limit) {
|
||||
clearInterval(intervalId)
|
||||
resolve(count)
|
||||
}
|
||||
}, timeout)
|
||||
})
|
||||
return position
|
||||
}
|
||||
Reference in New Issue
Block a user