Compare commits
7 Commits
653aadf1af
...
b40fef173f
Author | SHA1 | Date |
---|---|---|
|
b40fef173f | |
|
e222eb4779 | |
|
99f6446026 | |
|
b9c091ab8d | |
|
71c465f9c2 | |
|
0edad5d495 | |
|
3d6ede791a |
|
@ -389,7 +389,6 @@ globalThis.LCNSetting = class LCNSetting {
|
|||
this._id = null;
|
||||
this._eventId = null;
|
||||
this._label = null;
|
||||
this._hidden = false;
|
||||
this._value = null;
|
||||
this._valueDefault = null;
|
||||
|
||||
|
@ -406,8 +405,6 @@ globalThis.LCNSetting = class LCNSetting {
|
|||
}
|
||||
}
|
||||
|
||||
"isHidden" () { return this._hidden; }
|
||||
"setHidden" (v) { this._hidden = v; return this; }
|
||||
"getValue" () { return this._value || (this._value = this._getValue()); }
|
||||
"setValue" (v) {
|
||||
if (this._value !== v) {
|
||||
|
@ -424,10 +421,7 @@ globalThis.LCNSetting = class LCNSetting {
|
|||
"setDefaultValue" (vd) { this._valueDefault = vd; return this; }
|
||||
|
||||
"onChange" (fn) { $(document).on(`${this._eventId}::change`, (_,v,i) => fn(v, i)); }
|
||||
__setIdPrefix (prefix) {
|
||||
this._id = `${prefix}_${this._id}`
|
||||
this._eventId = `lcnsetting::${this._id}`
|
||||
}
|
||||
__setIdPrefix (prefix) { this._id = `${prefix}_${this._id}`; }
|
||||
}
|
||||
|
||||
globalThis.LCNToggleSetting = class LCNToggleSetting extends LCNSetting {
|
||||
|
@ -437,7 +431,7 @@ globalThis.LCNToggleSetting = class LCNToggleSetting extends LCNSetting {
|
|||
const div = document.createElement("div")
|
||||
const chk = document.createElement("input")
|
||||
const lbl = document.createElement("label")
|
||||
const id = `lcnts::${this.id}`
|
||||
const id = `${this._id}_input`
|
||||
lbl.htmlFor = id
|
||||
lbl.innerText = this.getLabel()
|
||||
chk.id = id
|
||||
|
@ -492,7 +486,7 @@ globalThis.LCNSettingsSubcategory = class LCNSettingsSubcategory {
|
|||
"addSetting" (setting) {
|
||||
assert.ok(setting instanceof LCNSetting)
|
||||
setting.__setIdPrefix(`lcnsetting_${this._tab_id}_${this._id}`)
|
||||
if (!setting.isHidden() && setting.__builtinDOMConstructor != null) {
|
||||
if (setting.__builtinDOMConstructor != null) {
|
||||
const div = setting.__builtinDOMConstructor()
|
||||
div.classList.add("lcn-setting-entry")
|
||||
this._fieldset.appendChild(div)
|
||||
|
|
|
@ -5,17 +5,12 @@
|
|||
|
||||
$().ready(() => {
|
||||
const kIsEnabled = LCNToggleSetting.build("enabled")
|
||||
const kUpdateOnReplyEnabled = LCNToggleSetting.build("updateOnReplyEnabled")
|
||||
//const kIsBellEnabled = LCNToggleSetting.build("bellEnabled")
|
||||
void LCNSettingsSubcategory.for("general", "threadUpdater")
|
||||
.setLabel("Thread Updater")
|
||||
.addSetting(kIsEnabled
|
||||
.setLabel(_("Fetch new replies in the background"))
|
||||
.setDefaultValue(true))
|
||||
.addSetting(kUpdateOnReplyEnabled
|
||||
.setLabel(_("Update thread after sending a reply"))
|
||||
.setHidden(true)
|
||||
.setDefaultValue(true))
|
||||
.setDefaultValue(true));
|
||||
/*.addSetting(kIsBellEnabled
|
||||
.setLabel(_("Play an audible chime when new replies are found"))
|
||||
.setDefaultValue(false))*/;
|
||||
|
@ -40,8 +35,8 @@ $().ready(() => {
|
|||
|
||||
const updateSecondsByTSLP = post_info => {
|
||||
secondsCounter = Math.floor(((Date.now() - post_info.getCreatedAt().getTime()) / 120000))
|
||||
secondsCounter = Math.min(1000, secondsCounter)
|
||||
secondsCounter = Math.max(11, secondsCounter)
|
||||
secondsCounter = secondsCounter > 1000 ? 1000 : secondsCounter
|
||||
secondsCounter = secondsCounter < 11 ? 11 : secondsCounter
|
||||
}
|
||||
|
||||
const updateStatsFn = async thread => {
|
||||
|
@ -63,7 +58,7 @@ $().ready(() => {
|
|||
}
|
||||
|
||||
const findMissingReplies = (thread_op, thread_dom, thread_latest) => {
|
||||
const lastPostTs = (cont(thread_dom.at(-1), x => x.getInfo()) || thread_op.getInfo()).getCreatedAt().getTime()
|
||||
const lastPostTs = (cont(thread_dom.at(-1), x => x.getInfo()) || thread_op).getCreatedAt().getTime()
|
||||
const missing = []
|
||||
|
||||
for (const pc of thread_latest.reverse()) {
|
||||
|
@ -136,7 +131,7 @@ $().ready(() => {
|
|||
|
||||
try {
|
||||
await updateStatsFn(thread)
|
||||
if (threadState == null && threadStats.last_modified > (thread.getPosts().at(-1).getInfo().getCreatedAt().getTime() / 1000)) {
|
||||
if (threadState == null && threadStats.last_modified > (thread.getReplies().at(-1).getInfo().getCreatedAt().getTime() / 1000)) {
|
||||
updateThreadFn(thread, await fetchThreadFn())
|
||||
}
|
||||
|
||||
|
@ -145,7 +140,7 @@ $().ready(() => {
|
|||
statReplies.innerText = thread.getReplies().length
|
||||
statFiles.innerText = threadEl.querySelectorAll(".files .file").length - threadEl.querySelectorAll(".files .file .post-image.deleted").length
|
||||
statPage.innerText = threadStats.page + 1
|
||||
updateSecondsByTSLP(thread.getPosts().at(-1).getInfo())
|
||||
updateSecondsByTSLP(thread.getReplies().at(-1).getInfo())
|
||||
} catch (error) {
|
||||
console.error("threadAutoUpdater: Failed while processing update. Probably a network error", error)
|
||||
secondsCounter = 60
|
||||
|
@ -157,29 +152,23 @@ $().ready(() => {
|
|||
|
||||
}
|
||||
|
||||
const refreshFn = () => {
|
||||
if (secondsCounter >= 0) {
|
||||
secondsCounter = 0
|
||||
onTickFn()
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on("ajax_after_post", (_, xhr_body) => {
|
||||
if (kUpdateOnReplyEnabled.getValue() && xhr_body != null) {
|
||||
if (xhr_body != null) {
|
||||
if (!xhr_body.mod) {
|
||||
const thread = LCNThread.first()
|
||||
const dom = parser.parseFromString(xhr_body.thread, "text/html")
|
||||
updateThreadFn(thread, dom)
|
||||
updateSecondsByTSLP(thread.getPosts().at(-1).getInfo())
|
||||
updateSecondsByTSLP(thread.getReplies().at(-1).getInfo())
|
||||
} else {
|
||||
refreshFn()
|
||||
$(document).trigger("thread_manual_refresh")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
$(document).on("thread_manual_refresh", () => {
|
||||
if (kIsEnabled.getValue()) {
|
||||
refreshFn()
|
||||
if (kIsEnabled.getValue() && secondsCounter >= 0) {
|
||||
secondsCounter = 0
|
||||
onTickFn()
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue