“);
}
}
var out = “”;
if (styles.length) out += “”;
out += html.join(“”);
return out;
}
function formatDate(iso) {
try {
var d = new Date(iso);
if (isNaN(d.getTime())) return esc(iso);
return esc(d.toLocaleString(undefined, { dateStyle: “long”, timeStyle: “short” }));
} catch (e) {
return esc(iso);
}
}
function authorHtml(a) {
var bits = [“By:”];
if (a.publisher && a.provider && a.publisher !== a.provider) {
bits.push(” ” + esc(a.publisher) + ” via”);
}
bits.push(” ” + esc(a.provider || a.providerCode || “”) + “”);
return bits.join(“”);
}
function renderArticle(a, body) {
var href = articleHref(a.slug);
var path = pathForPush(href);
var photo = “”;
if (a.showPhotoInBody && a.photo) {
photo = ‘
‘;
}
var report =
“https://zfrmz.com/JouiiK8kl2AnTJwaW0Hf?url=” +
encodeURIComponent(href) +
“&slug=” +
encodeURIComponent(a.slug);
var wrap = document.createElement(“div”);
wrap.className = “fc-continuum-item”;
wrap.setAttribute(“data-slug”, a.slug);
wrap.innerHTML =
” +
” +
” +
” +
‘
‘ +
esc(a.headline) +
“
” +
” +
authorHtml(a) +
”
” +
” +
formatDate(a.date) +
”
” +
‘ⓘ This article is third-party content and does not represent the views of this site. We make no guarantees regarding its accuracy or completeness.
‘ +
” +
photo +
bodyHtml(body) +
”
” +
‘Report this content‘ +
“
If you believe this article contains misleading, harmful, or spam content, please let us know.
” +
‘Report this article
‘ +
”
“;
return wrap;
}
function reinjectAds(scope) {
try {
var slots = scope.querySelectorAll(“ins.adsbygoogle”);
for (var i = 0; i < slots.length; i++) {
if (!slots[i].getAttribute(“data-adsbygoogle-status”)) {
(window.adsbygoogle = window.adsbygoogle || []).push({});
}
}
// Nudge AdSense Auto ads to notice new DOM length.
(window.adsbygoogle = window.adsbygoogle || []).push({});
} catch (e) {}
try {
if (window.dianomi && typeof window.dianomi.refresh === “function”) {
window.dianomi.refresh();
} else if (typeof window.dianomiContextScriptLoaded !== “undefined”) {
// contextfeed.js already on page â new .dianomi_context nodes picked up on refresh if available
}
} catch (e) {}
}
function fetchBody(bodyId) {
return fetch(cfg.bodyBase + encodeURIComponent(bodyId), {
method: “GET”,
credentials: “omit”,
cache: “no-store”,
headers: { Authorization: cfg.auth },
}).then(function (res) {
if (!res.ok) throw new Error(“body ” + res.status);
return res.json();
});
}
function loadNext() {
if (loading || exhausted) return;
if (loaded >= queue.length) {
exhausted = true;
sentinel.classList.add(“is-done”);
return;
}
loading = true;
sentinel.classList.add(“is-loading”);
var next = queue[loaded];
fetchBody(next.bodyId)
.then(function (data) {
if (!data || !data.body) throw new Error(“empty body”);
var node = renderArticle(next, data.body);
root.appendChild(node);
loaded += 1;
reinjectAds(node);
if (loaded >= queue.length) {
exhausted = true;
sentinel.classList.add(“is-done”);
}
})
.catch(function () {
// Skip bad item and continue.
loaded += 1;
if (loaded >= queue.length) {
exhausted = true;
sentinel.classList.add(“is-done”);
}
})
.then(function () {
loading = false;
sentinel.classList.remove(“is-loading”);
});
}
function nearBottom() {
var rect = sentinel.getBoundingClientRect();
return rect.top < window.innerHeight + 400;
}
function onScroll() {
if (nearBottom()) loadNext();
}
function syncPath() {
var markers = document.getElementsByClassName(“infiniteScrollPathMarker”);
var scrollBottom = window.scrollY + window.innerHeight;
var path = null;
var title = null;
for (var i = 0; i < markers.length; i++) {
var m = markers[i];
if (m.offsetTop < scrollBottom) {
path = pathForPush(m.getAttribute(“data-path”) || “”);
var art = m.closest(“article”);
var h = art && art.querySelector(“.title”);
if (h) title = h.textContent;
}
}
if (path && path !== window.location.pathname + window.location.search) {
window.history.pushState(null, “”, path);
}
if (title) document.title = title;
}
var syncTimer = null;
function onScrollPath() {
if (syncTimer) return;
syncTimer = setTimeout(function () {
syncTimer = null;
syncPath();
}, 200);
}
window.addEventListener(“scroll”, onScroll, { passive: true });
window.addEventListener(“scroll”, onScrollPath, { passive: true });
// Kick once in case first article is short.
onScroll();
})();
