Finally fixed and tested

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

View File

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

View File

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