Filter out invisible elements

This commit is contained in:
Idrees Hassan
2025-10-28 23:28:12 -04:00
parent 1061f978b5
commit ea1f08c80d
4 changed files with 31 additions and 10 deletions

13
dist/birb.js vendored
View File

@@ -1675,7 +1675,7 @@
insertModal(`${birdBirb()} Mode`, message);
}),
new Separator(),
new MenuItem("2025.10.28.157", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.10.28.157"); }, false),
new MenuItem("2025.10.28.165", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.10.28.165"); }, false),
];
const styleElement = document.createElement("style");
@@ -1928,7 +1928,7 @@
function update() {
ticks++;
// Hide bird if the browser is fullscreen
if (document.fullscreenElement) {
birb.setVisible(false);
@@ -2342,9 +2342,16 @@
const rect = img.getBoundingClientRect();
return rect.left >= 0 && rect.top >= MIN_FOCUS_ELEMENT_TOP && rect.right <= window.innerWidth && rect.top <= getWindowHeight();
});
const visible = Array.from(inWindow).filter((img) => {
const style = window.getComputedStyle(img);
if (style.display === "none" || style.visibility === "hidden" || (style.opacity && parseFloat(style.opacity) < 0.25)) {
return false;
}
return true;
});
/** @type {HTMLElement[]} */
// @ts-expect-error
const largeElements = Array.from(inWindow).filter((img) => img instanceof HTMLElement && img !== focusedElement && img.offsetWidth >= MIN_FOCUS_ELEMENT_WIDTH);
const largeElements = Array.from(visible).filter((img) => img instanceof HTMLElement && img !== focusedElement && img.offsetWidth >= MIN_FOCUS_ELEMENT_WIDTH);
// Ensure the bird doesn't land on fixed or sticky elements
const nonFixedElements = largeElements.filter((el) => {
const style = window.getComputedStyle(el);