Skip to content

Instantly share code, notes, and snippets.

@eioo
Created April 15, 2018 12:28
Show Gist options
  • Save eioo/58f7f8fe3429eab301c12c89e67e6f6e to your computer and use it in GitHub Desktop.
Save eioo/58f7f8fe3429eab301c12c89e67e6f6e to your computer and use it in GitHub Desktop.
function loadNewReplies(t) {
if (updateRunning) return !1;
if ($("#msg").is(":focus")) return autoupdate && (nextReplyUpdateTimeout = setTimeout(function () {
loadNewReplies(t)
}, 2e3)), !1;
var e = $$(t).find(".answers .answer:last");
if (e.is("*")) var s = e.attr("id").replace("no", "");
else var s = 1;
if (0 == t.length || 0 == s.length) return !1;
updateRunning = !0, $.get(siteUrl + "/scripts/ajax/get_new_replies.php", {
thread: t,
latest_reply: s
}, function (e) {
if (updateRunning = !1, e.html) updateRetryCount = 0;
else if ((updateRetryCount += 1) > 30) return void stopReplyUpdate();
if (autoupdate && (nextReplyUpdateTimeout = setTimeout(function () {
loadNewReplies(t)
}, 2e3 * (updateRetryCount + 1))), void 0 !== e.unreadCount && void 0 !== e.html && 0 != e.unreadCount.length && 0 != e.html.length) {
unreadCount += e.unreadCount, document.hasFocus() ? unreadCount = 0 : document.title = "(" + unreadCount + ") " + documentTitle;
var i = $("form#post input, form#post textarea").is(":focus"),
o = $(document).height() - ($(window).scrollTop() + window.innerHeight);
$$(t).find(".answers").append(e.html.replace('class="answer', 'class="answer addlinks')), s = $(".answer:last-of-type").attr("id").replace("no", ""), updateQuotes(), $(".answer.addlinks").each(function () {
$(this).children(".post").each(function () {
$(this).clickableLinks()
}), $(this).removeClass("addlinks")
}), i && $(window).scrollTop($(document).height() - window.innerHeight - o)
}
}).fail(function () {
updateRunning = !1, stopReplyUpdate()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment