26 lines
802 B
JavaScript
26 lines
802 B
JavaScript
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
|
|
} |