Update Bluesky.ts
Added a filter to only visible elements to reduce clutter from posts in feed.master
parent
1575a7a2f1
commit
fe0a543bf4
|
|
@ -39,6 +39,8 @@ export default class Bluesky extends ScrapeEngineBase {
|
|||
els = imgEls.filter((x) => x.src.indexOf("feed") != -1);
|
||||
}
|
||||
for (const el of els) {
|
||||
if(!isVisible(el)) continue;
|
||||
|
||||
const post = new ScrapedPost();
|
||||
post.pageUrl = document.location.href;
|
||||
post.contentUrl = getFullSizeImg(el.src);
|
||||
|
|
@ -50,6 +52,8 @@ export default class Bluesky extends ScrapeEngineBase {
|
|||
document.querySelectorAll('video[poster^="https://video.bsky.app/watch"]')
|
||||
);
|
||||
for (const v of videoEls) {
|
||||
if(!isVisible(v)) continue;
|
||||
|
||||
const poster = v.getAttribute("poster");
|
||||
if (!poster) continue;
|
||||
|
||||
|
|
@ -102,3 +106,21 @@ export default class Bluesky extends ScrapeEngineBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A lightweight visibility check. We use this rather than IntersectionObserver
|
||||
* because scrapeDocument is synchronous and must return immediately.
|
||||
*/
|
||||
function isVisible(el: Element): boolean {
|
||||
const rect = el.getBoundingClientRect();
|
||||
if (rect.width === 0 || rect.height === 0) return false;
|
||||
if (rect.bottom <= 0 || rect.top >= window.innerHeight) return false;
|
||||
if (rect.right <= 0 || rect.left >= window.innerWidth) return false;
|
||||
|
||||
const style = window.getComputedStyle(el);
|
||||
if (style.display === "none") return false;
|
||||
if (style.visibility === "hidden") return false;
|
||||
if (style.opacity === "0") return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
Loading…
Reference in New Issue