parent
38ad7b1156
commit
1575a7a2f1
|
|
@ -26,21 +26,23 @@ export default class Bluesky extends ScrapeEngineBase {
|
|||
|
||||
scrapeDocument(document: Document): ScrapeResult {
|
||||
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"));
|
||||
|
||||
let els = imgEls.filter((x) => x.src.indexOf("feed_fullsize") != -1);
|
||||
|
||||
// Only add the 'normal' feed elements if no post is in fullscreen.
|
||||
if (els.length == 0) {
|
||||
this.log("Post is not fullscreen.");
|
||||
els = imgEls.filter((x) => x.src.indexOf("feed") != -1);
|
||||
}
|
||||
|
||||
for (const el of els) {
|
||||
const post = new ScrapedPost();
|
||||
post.pageUrl = document.location.href;
|
||||
post.contentUrl = getFullSizeImg(el.src);
|
||||
result.tryAddPost(post);
|
||||
candidates.push({ el, post });
|
||||
}
|
||||
|
||||
// Videos
|
||||
|
|
@ -56,14 +58,22 @@ export default class Bluesky extends ScrapeEngineBase {
|
|||
this.log(`Could not parse poster URL: ${poster}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const post = new ScrapedPost();
|
||||
post.pageUrl = document.location.href;
|
||||
post.contentUrl = blobUrl;
|
||||
post.contentType = "video";
|
||||
result.tryAddPost(post);
|
||||
candidates.push({ el: v, 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue