recent_posts.js: fix ::new_posts firing wrong element
This commit is contained in:
parent
ac29d60517
commit
c358bb0da7
|
@ -40,10 +40,6 @@
|
||||||
let liveUpdateIntervalId = null
|
let liveUpdateIntervalId = null
|
||||||
let liveUpdateFaviconChanged = false
|
let liveUpdateFaviconChanged = false
|
||||||
|
|
||||||
const getChanComment = el => Array.prototype.find.apply(el.children, [
|
|
||||||
el => el.classList.contains("thread") || el.classList.contains("postcontainer")
|
|
||||||
])
|
|
||||||
|
|
||||||
const parser = new DOMParser()
|
const parser = new DOMParser()
|
||||||
const fetchLatest = async () => {
|
const fetchLatest = async () => {
|
||||||
const res = await fetch(`/mod.php?/recent/${kPullXPosts}`, {
|
const res = await fetch(`/mod.php?/recent/${kPullXPosts}`, {
|
||||||
|
@ -53,10 +49,12 @@
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const dom = parser.parseFromString(await res.text(), "text/html")
|
const dom = parser.parseFromString(await res.text(), "text/html")
|
||||||
const posts = Array.from(dom.querySelectorAll("body > .post-wrapper[data-board]"))
|
const posts = Array.from(dom.querySelectorAll("body > .post-wrapper[data-board]"))
|
||||||
|
const eita = Array.prototype.find.apply(el.children, [ el => el.classList.contains("eita-link") ])
|
||||||
return posts.map(el => ({
|
return posts.map(el => ({
|
||||||
"element": el,
|
"element": el,
|
||||||
"href": Array.prototype.find.apply(el.children, [ el => el.classList.contains("eita-link") ]).href,
|
"post": el.querySelector(".thread, .post"),
|
||||||
"id": getChanComment(el).id
|
"href": eita.href,
|
||||||
|
"id": eita.id
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
return []
|
return []
|
||||||
|
@ -84,7 +82,7 @@
|
||||||
|
|
||||||
// XXX: Fire ::new_post for chanx listeners
|
// XXX: Fire ::new_post for chanx listeners
|
||||||
for (const post of posts.slice(0, kRecentXPosts)) {
|
for (const post of posts.slice(0, kRecentXPosts)) {
|
||||||
$(document).trigger("new_post", [ getChanComment(post.element) ])
|
$(document).trigger("new_post", [ post.post ])
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePageNext()
|
updatePageNext()
|
||||||
|
|
Loading…
Reference in New Issue