stop scrolling when cant scroll (#771)

This commit is contained in:
LawyZheng
2024-09-04 02:31:04 +08:00
committed by GitHub
parent 2ba0309602
commit 069597e52e
2 changed files with 63 additions and 21 deletions

View File

@@ -1372,6 +1372,11 @@ function drawBoundingBoxes(elements) {
addHintMarkersToPage(hintMarkers);
}
function buildElementsAndDrawBoundingBoxes() {
var elementsAndResultArray = buildTreeFromBody();
drawBoundingBoxes(elementsAndResultArray[0]);
}
function captchaSolvedCallback() {
console.log("captcha solved");
if (!window["captchaSolvedCounter"]) {
@@ -1556,8 +1561,7 @@ function scrollToTop(draw_boxes) {
removeBoundingBoxes();
window.scroll({ left: 0, top: 0, behavior: "instant" });
if (draw_boxes) {
var elementsAndResultArray = buildTreeFromBody();
drawBoundingBoxes(elementsAndResultArray[0]);
buildElementsAndDrawBoundingBoxes();
}
return window.scrollY;
}
@@ -1572,12 +1576,30 @@ function scrollToNextPage(draw_boxes) {
behavior: "instant",
});
if (draw_boxes) {
var elementsAndResultArray = buildTreeFromBody();
drawBoundingBoxes(elementsAndResultArray[0]);
buildElementsAndDrawBoundingBoxes();
}
return window.scrollY;
}
function isWindowScrollable() {
// Check if the body's overflow style is set to hidden
const bodyOverflow = window.getComputedStyle(document.body).overflow;
const htmlOverflow = window.getComputedStyle(
document.documentElement,
).overflow;
// Check if the document height is greater than the window height
const isScrollable =
document.documentElement.scrollHeight > window.innerHeight;
// If the overflow is set to 'hidden' or there is no content to scroll, return false
if (bodyOverflow === "hidden" || htmlOverflow === "hidden" || !isScrollable) {
return false;
}
return true;
}
function scrollToElementBottom(element, page_by_page = false) {
const top = page_by_page
? element.clientHeight + element.scrollTop