From ea1f08c80de530b710c10a612eaa9b3c8ba4392c Mon Sep 17 00:00:00 2001 From: Idrees Hassan Date: Tue, 28 Oct 2025 23:28:12 -0400 Subject: [PATCH] Filter out invisible elements --- dist/birb.js | 13 ++++++++++--- dist/birb.user.js | 15 +++++++++++---- manifest.json | 2 +- src/application.js | 11 +++++++++-- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/dist/birb.js b/dist/birb.js index 5ecfde9..5d5f5a4 100644 --- a/dist/birb.js +++ b/dist/birb.js @@ -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); diff --git a/dist/birb.user.js b/dist/birb.user.js index d35fe14..8158d7c 100644 --- a/dist/birb.user.js +++ b/dist/birb.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Pocket Bird // @namespace https://idreesinc.com -// @version 2025.10.28.157 +// @version 2025.10.28.165 // @description birb // @author Idrees // @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/birb.user.js @@ -1689,7 +1689,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"); @@ -1942,7 +1942,7 @@ function update() { ticks++; - + // Hide bird if the browser is fullscreen if (document.fullscreenElement) { birb.setVisible(false); @@ -2356,9 +2356,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); diff --git a/manifest.json b/manifest.json index 5c96a05..81aae1e 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "Pocket Bird", "description": "It's a bird, in your browser. What more could you want?", - "version": "2025.10.28.157", + "version": "2025.10.28.165", "homepage_url": "https://idreesinc.com", "icons": { "48": "images/icons/transparent/48x48x1.png", diff --git a/src/application.js b/src/application.js index 4a49d6a..a11ce24 100644 --- a/src/application.js +++ b/src/application.js @@ -480,7 +480,7 @@ Promise.all([ function update() { ticks++; - + // Hide bird if the browser is fullscreen if (document.fullscreenElement) { birb.setVisible(false); @@ -898,9 +898,16 @@ Promise.all([ 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);