Compare commits
No commits in common. "fe0a543bf4e304e655bb3ec288b3c277d740051e" and "38ad7b11568afb815075b0612378175d79304844" have entirely different histories.
fe0a543bf4
...
38ad7b1156
|
|
@ -26,25 +26,21 @@ export default class Bluesky extends ScrapeEngineBase {
|
||||||
|
|
||||||
scrapeDocument(document: Document): ScrapeResult {
|
scrapeDocument(document: Document): ScrapeResult {
|
||||||
const result = new ScrapeResult(this.name);
|
const result = new ScrapeResult(this.name);
|
||||||
|
|
||||||
type Candidate = { el: Element; post: ScrapedPost };
|
|
||||||
const candidates: Candidate[] = [];
|
|
||||||
|
|
||||||
// Images
|
|
||||||
const imgEls = Array.from<HTMLImageElement>(document.querySelectorAll("div > img"));
|
const imgEls = Array.from<HTMLImageElement>(document.querySelectorAll("div > img"));
|
||||||
|
|
||||||
let els = imgEls.filter((x) => x.src.indexOf("feed_fullsize") != -1);
|
let els = imgEls.filter((x) => x.src.indexOf("feed_fullsize") != -1);
|
||||||
|
|
||||||
// Only add the 'normal' feed elements if no post is in fullscreen.
|
// Only add the 'normal' feed elements if no post is in fullscreen.
|
||||||
if (els.length == 0) {
|
if (els.length == 0) {
|
||||||
this.log("Post is not fullscreen.");
|
this.log("Post is not fullscreen.");
|
||||||
els = imgEls.filter((x) => x.src.indexOf("feed") != -1);
|
els = imgEls.filter((x) => x.src.indexOf("feed") != -1);
|
||||||
}
|
}
|
||||||
for (const el of els) {
|
|
||||||
if(!isVisible(el)) continue;
|
|
||||||
|
|
||||||
|
for (const el of els) {
|
||||||
const post = new ScrapedPost();
|
const post = new ScrapedPost();
|
||||||
post.pageUrl = document.location.href;
|
post.pageUrl = document.location.href;
|
||||||
post.contentUrl = getFullSizeImg(el.src);
|
post.contentUrl = getFullSizeImg(el.src);
|
||||||
candidates.push({ el, post });
|
result.tryAddPost(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Videos
|
// Videos
|
||||||
|
|
@ -52,8 +48,6 @@ export default class Bluesky extends ScrapeEngineBase {
|
||||||
document.querySelectorAll('video[poster^="https://video.bsky.app/watch"]')
|
document.querySelectorAll('video[poster^="https://video.bsky.app/watch"]')
|
||||||
);
|
);
|
||||||
for (const v of videoEls) {
|
for (const v of videoEls) {
|
||||||
if(!isVisible(v)) continue;
|
|
||||||
|
|
||||||
const poster = v.getAttribute("poster");
|
const poster = v.getAttribute("poster");
|
||||||
if (!poster) continue;
|
if (!poster) continue;
|
||||||
|
|
||||||
|
|
@ -62,22 +56,14 @@ export default class Bluesky extends ScrapeEngineBase {
|
||||||
this.log(`Could not parse poster URL: ${poster}`);
|
this.log(`Could not parse poster URL: ${poster}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const post = new ScrapedPost();
|
const post = new ScrapedPost();
|
||||||
post.pageUrl = document.location.href;
|
post.pageUrl = document.location.href;
|
||||||
post.contentUrl = blobUrl;
|
post.contentUrl = blobUrl;
|
||||||
post.contentType = "video";
|
post.contentType = "video";
|
||||||
candidates.push({ el: v, post });
|
result.tryAddPost(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
candidates.sort((a, b) => {
|
|
||||||
const pos = a.el.compareDocumentPosition(b.el);
|
|
||||||
if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
|
|
||||||
if (pos & Node.DOCUMENT_POSITION_PRECEDING) return 1;
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
for(const c of candidates) result.tryAddPost(c.post);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,21 +92,3 @@ 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