mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-21 23:57:30 +00:00
Embeds may be blocked or have missing captions
This commit is contained in:
parent
09b33ef3fa
commit
a6094a37ec
@ -431,6 +431,12 @@ function fetchShortcodeData(shortcode) {
|
|||||||
|
|
||||||
// find embed
|
// find embed
|
||||||
const e_embed = root.querySelector(".Embed")
|
const e_embed = root.querySelector(".Embed")
|
||||||
|
// rate limited? if so, the request to instagram took 5-10 seconds, and returned no other content after <body style="background: white">
|
||||||
|
// so in that case there will be no useful elements, and no .Embed element
|
||||||
|
if (!e_embed) {
|
||||||
|
throw constants.symbols.RATE_LIMITED
|
||||||
|
}
|
||||||
|
|
||||||
// find avatar
|
// find avatar
|
||||||
const e_avatar = root.querySelector(".Avatar")
|
const e_avatar = root.querySelector(".Avatar")
|
||||||
const e_avatarImage = e_avatar.querySelector("img")
|
const e_avatarImage = e_avatar.querySelector("img")
|
||||||
@ -473,13 +479,16 @@ function fetchShortcodeData(shortcode) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
// extract caption text
|
// extract caption text
|
||||||
const captionText = e_caption.childNodes.slice(4, -3).map(node => { // slice removes unneeded starting and ending whitespace and user handles
|
let captionText = ""
|
||||||
|
if (e_caption) {
|
||||||
|
captionText = e_caption.childNodes.slice(4, -3).map(node => { // slice removes unneeded starting and ending whitespace and user handles
|
||||||
if (node.tagName === "br") {
|
if (node.tagName === "br") {
|
||||||
return "\n"
|
return "\n"
|
||||||
} else {
|
} else {
|
||||||
return node.text
|
return node.text
|
||||||
}
|
}
|
||||||
}).join("")
|
}).join("")
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
__typename: mediaType,
|
__typename: mediaType,
|
||||||
id: e_embed.attributes["data-media-id"],
|
id: e_embed.attributes["data-media-id"],
|
||||||
|
Loading…
Reference in New Issue
Block a user