Skip to content

Commit

Permalink
Fix #50
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrews54757 committed Dec 17, 2023
1 parent 2507691 commit 83127b8
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions chrome/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,20 +348,40 @@ function isVisible(domElement) {
});
}

function parentHasSimilarBounds(element) {
const parent = element.parentElement;
const rect = element.getBoundingClientRect();
const parentRect = parent.getBoundingClientRect();
const tolerance = 4;
if ( // First check
Math.abs(rect.x - parentRect.x) < tolerance &&
Math.abs(rect.y - parentRect.y) < tolerance &&
Math.abs(rect.width - parentRect.width) < tolerance &&
Math.abs(rect.height - parentRect.height) < tolerance
) {
return true;
}

// Check if parent element is overflow hidden and child element can cover the parent element
const parentStyle = window.getComputedStyle(parent);
if (parentStyle.overflow === 'hidden') {
if (rect.x <= parentRect.x &&
rect.y <= parentRect.y &&
rect.x + rect.width >= parentRect.x + parentRect.width &&
rect.y + rect.height >= parentRect.y + parentRect.height) {
return true;
}
}

return false;
}

function getParentElementsWithSameBounds(element) {
const elements = [];
const tolerance = 4;

while (element.parentElement) {
const parent = element.parentElement;
const rect = element.getBoundingClientRect();
const parentRect = parent.getBoundingClientRect();
if (
Math.abs(rect.x - parentRect.x) < tolerance &&
Math.abs(rect.y - parentRect.y) < tolerance &&
Math.abs(rect.width - parentRect.width) < tolerance &&
Math.abs(rect.height - parentRect.height) < tolerance
) {
if (parentHasSimilarBounds(element)) {
elements.push(parent);
} else {
break;
Expand Down

0 comments on commit 83127b8

Please sign in to comment.