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