Finally fixed and tested

This commit is contained in:
towards-a-new-leftypol 2024-02-27 20:42:36 +00:00
parent 824ffc3385
commit c8f460aa9d
3 changed files with 19 additions and 31 deletions

View File

@ -215,12 +215,7 @@ globalThis.LCNPost = class LCNPost {
this._post = post; this._post = post;
this._info = LCNPostInfo.assign(post); this._info = LCNPostInfo.assign(post);
this._ipLink = intro.querySelector(".ip-link"); this._ipLink = intro.querySelector(".ip-link");
this._controls = Array.prototype.at.apply(post.querySelectorAll(".controls"), [ -1 ]);
//this._controls = Array.prototype.at.apply(post.querySelectorAll(".controls"), [ -1 ]);
// the above line fails on older browsers so do this instead:
const elements = Array.prototype.slice.call(post.querySelectorAll(".controls"));
this._controls = elements[elements.length - 1];
//assert.equal(this._info.getParent(), null, "Info should not have parent."); //assert.equal(this._info.getParent(), null, "Info should not have parent.");
this._info.__setParent(this); this._info.__setParent(this);
} }
@ -435,8 +430,11 @@ globalThis.LCNToggleSetting = class LCNToggleSetting extends LCNSetting {
__builtinDOMConstructor () { __builtinDOMConstructor () {
const div = document.createElement("div") const div = document.createElement("div")
const chk = document.createElement("input") const chk = document.createElement("input")
const txt = document.createElement("label") const lbl = document.createElement("label")
txt.innerText = this.getLabel() const id = `${this._id}_input`
lbl.htmlFor = id
lbl.innerText = this.getLabel()
chk.id = id
chk.type = "checkbox" chk.type = "checkbox"
chk.checked = this.getValue() chk.checked = this.getValue()
chk.addEventListener("click", e => { chk.addEventListener("click", e => {
@ -446,7 +444,7 @@ globalThis.LCNToggleSetting = class LCNToggleSetting extends LCNSetting {
this.onChange(v => chk.checked = v) this.onChange(v => chk.checked = v)
div.appendChild(chk) div.appendChild(chk)
div.appendChild(txt) div.appendChild(lbl)
return div return div
} }
} }

View File

@ -16,7 +16,6 @@ $().ready(() => {
.setDefaultValue(false))*/; .setDefaultValue(false))*/;
if (LCNSite.INSTANCE.isThreadPage()) { if (LCNSite.INSTANCE.isThreadPage()) {
console.log("LCNSite.INSTANCE.isThreadPage() is true");
let threadUpdateStatus = null let threadUpdateStatus = null
let secondsCounter = 0 let secondsCounter = 0
let threadState = null let threadState = null
@ -122,52 +121,39 @@ $().ready(() => {
let onTickId = null let onTickId = null
const onTickFn = async () => { const onTickFn = async () => {
console.log("tick function");
void secondsCounter--; void secondsCounter--;
console.log(secondsCounter);
onTickClean() onTickClean()
updateDOMStatus() updateDOMStatus()
console.log("tick function2");
if (threadState == null) { if (threadState == null) {
console.log("tick function3");
console.log(secondsCounter);
if (secondsCounter < 0) { if (secondsCounter < 0) {
console.log("tick function3.5");
const thread = LCNThread.first() const thread = LCNThread.first()
console.log("tick function4");
try { try {
await updateStatsFn(thread) await updateStatsFn(thread)
if (threadState == null && threadStats.last_modified > (thread.getReplies().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())
} }
console.log("tick function5");
const threadEl = thread.getElement() const threadEl = thread.getElement()
statUniqueIPs.innerText = threadStats.unique_ips statUniqueIPs.innerText = threadStats.unique_ips
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.getReplies().at(-1).getInfo()) updateSecondsByTSLP(thread.getReplies().at(-1).getInfo())
console.log("tick function6");
} 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
} }
} }
//onTickId = setTimeout(onTickFn, 1000) onTickId = setTimeout(onTickFn, 1000)
} }
console.log("bottom of tick function");
} }
$(document).on("ajax_after_post", (_, xhr_body) => { $(document).on("ajax_after_post", (_, xhr_body) => {
if (kIsEnabled.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")
@ -182,18 +168,15 @@ $().ready(() => {
$(document).on("thread_manual_refresh", () => { $(document).on("thread_manual_refresh", () => {
if (kIsEnabled.getValue() && secondsCounter >= 0) { if (kIsEnabled.getValue() && secondsCounter >= 0) {
secondsCounter = 0 secondsCounter = 0
console.log("thread_manual_refresh handler");
onTickFn() onTickFn()
} }
}) })
let floaterLinkBox = null let floaterLinkBox = null
const onStateChangeFn = v => { const onStateChangeFn = v => {
console.log("onStateChangeFn");
onTickClean() onTickClean()
if (v) { if (v) {
console.log("v is true");
_domsetup_btn: { _domsetup_btn: {
const container = LCNSite.INSTANCE.getFloaterLContainer() const container = LCNSite.INSTANCE.getFloaterLContainer()
floaterLinkBox = document.createElement("span") floaterLinkBox = document.createElement("span")
@ -249,10 +232,8 @@ $().ready(() => {
} }
} }
console.log("thread_manual_refresh trigger");
$(document).trigger("thread_manual_refresh") $(document).trigger("thread_manual_refresh")
} else { } else {
console.log("v is false");
cont(floaterLinkBox, x => x.remove()) cont(floaterLinkBox, x => x.remove())
floaterLinkBox = null floaterLinkBox = null
statReplies = null statReplies = null
@ -267,6 +248,5 @@ $().ready(() => {
kIsEnabled.onChange(onStateChangeFn) kIsEnabled.onChange(onStateChangeFn)
onStateChangeFn(kIsEnabled.getValue()) onStateChangeFn(kIsEnabled.getValue())
console.log("Bottom of if block");
} }
}) })

View File

@ -101,3 +101,13 @@ if( Node.prototype.replaceChildren === undefined) {
} }
} }
} }
if (Array.prototype.at === undefined) {
Array.prototype.at = function(index) {
if (index >= 0) {
return this[index];
} else {
return this[this.length + index];
}
};
}