thread_autoupdater.js: spin-off update on reply

This commit is contained in:
Jon 2024-02-27 22:56:00 +00:00 committed by towards-a-new-leftypol
parent dd80ea013a
commit 9127429b8f
1 changed files with 16 additions and 5 deletions

View File

@ -6,12 +6,17 @@
$().ready(() => { $().ready(() => {
const kIsEnabled = LCNToggleSetting.build("enabled") const kIsEnabled = LCNToggleSetting.build("enabled")
const kUpdateOnReplyEnabled = LCNToggleSetting.build("updateOnReplyEnabled")
//const kIsBellEnabled = LCNToggleSetting.build("bellEnabled") //const kIsBellEnabled = LCNToggleSetting.build("bellEnabled")
void LCNSettingsSubcategory.for("general", "threadUpdater") void LCNSettingsSubcategory.for("general", "threadUpdater")
.setLabel("Thread Updater") .setLabel("Thread Updater")
.addSetting(kIsEnabled .addSetting(kIsEnabled
.setLabel(_("Fetch new replies in the background")) .setLabel(_("Fetch new replies in the background"))
.setDefaultValue(true)) .setDefaultValue(true))
.addSetting(kUpdateOnReplyEnabled
.setLabel(_("Update thread after sending a reply"))
.setHidden(true)
.setDefaultValue(true))
/*.addSetting(kIsBellEnabled /*.addSetting(kIsBellEnabled
.setLabel(_("Play an audible chime when new replies are found")) .setLabel(_("Play an audible chime when new replies are found"))
.setDefaultValue(false))*/; .setDefaultValue(false))*/;
@ -151,23 +156,29 @@ $().ready(() => {
} }
} }
const refreshFn = () => {
if (secondsCounter >= 0) {
secondsCounter = 0
onTickFn()
}
}
$(document).on("ajax_after_post", (_, xhr_body) => { $(document).on("ajax_after_post", (_, xhr_body) => {
if (kIsEnabled.getValue() && xhr_body != null) { if (kUpdateOnReplyEnabled.getValue() && xhr_body != null) {
if (!xhr_body.mod) { if (!xhr_body.mod) {
const thread = LCNThread.first() const thread = LCNThread.first()
const dom = parser.parseFromString(xhr_body.thread, "text/html") const dom = parser.parseFromString(xhr_body.thread, "text/html")
updateThreadFn(thread, dom) updateThreadFn(thread, dom)
updateSecondsByTSLP(thread.getPosts().at(-1).getInfo()) updateSecondsByTSLP(thread.getPosts().at(-1).getInfo())
} else { } else {
$(document).trigger("thread_manual_refresh") refreshFn()
} }
} }
}) })
$(document).on("thread_manual_refresh", () => { $(document).on("thread_manual_refresh", () => {
if (kIsEnabled.getValue() && secondsCounter >= 0) { if (kIsEnabled.getValue()) {
secondsCounter = 0 refreshFn()
onTickFn()
} }
}) })