Compare commits

...

4 Commits

3 changed files with 473 additions and 387 deletions

View File

@ -33,7 +33,7 @@ globalThis.LCNSite = class LCNSite {
return null return null
}; };
static "constructor" () { constructor () {
this._isModerator = document.body.classList.contains("is-moderator"); this._isModerator = document.body.classList.contains("is-moderator");
this._isThreadPage = document.body.classList.contains("active-thread"); this._isThreadPage = document.body.classList.contains("active-thread");
@ -47,16 +47,18 @@ globalThis.LCNSite = class LCNSite {
this._unseen = 0; this._unseen = 0;
this._pageTitle = document.title; this._pageTitle = document.title;
this._doTitleUpdate = () => {
document.title = (this._unseen > 0 ? `(${this._unseen}) ` : "") + this._pageTitle;
};
this._favicon = document.querySelector("head > link[rel=\"shortcut icon\"]"); this._favicon = document.querySelector("head > link[rel=\"shortcut icon\"]");
this._generatedStyle = null; this._generatedStyle = null;
} }
"_doTitleUpdate" () {
document.title = (this._unseen > 0 ? `(${this._unseen}) ` : "") + this._pageTitle;
};
"isModerator" () { return this._isModerator; } "isModerator" () { return this._isModerator; }
"isThreadPage" () { return this._isThreadPage; } "isThreadPage" () {
return this._isThreadPage;
}
"isBoardPage" () { return this._isBoardPage; } "isBoardPage" () { return this._isBoardPage; }
"isCatalogPage" () { return this._isCatalogPage; } "isCatalogPage" () { return this._isCatalogPage; }
@ -105,11 +107,11 @@ globalThis.LCNSite = class LCNSite {
} }
LCNSite.INSTANCE = null; globalThis.LCNSite.INSTANCE = null;
globalThis.LCNPostInfo = class LCNPostInfo { globalThis.LCNPostInfo = class LCNPostInfo {
static "constructor" () { constructor () {
this._boardId = null; this._boardId = null;
this._threadId = null; this._threadId = null;
this._postId = null; this._postId = null;
@ -128,384 +130,397 @@ globalThis.LCNPostInfo = class LCNPostInfo {
} }
static "assign" (post) { return post[this.nodeAttrib] ?? (post[this.nodeAttrib] = this.from(post)); } static "assign" (post) {
static "from" (post) { if (post[this.nodeAttrib] == null) {
assert.ok(post.classList.contains("post"), "Arty must be expected Element.") return post[this.nodeAttrib] = this.from(post);
const inst = new this() } else {
const intro = post.querySelector(".intro") return post[this.nodeAttrib];
const link = intro.querySelector(".post_no:not([id])").href.split("/").reverse() }
inst.#postId = link[0].slice(link[0].indexOf("#q") + 2)
inst.#threadId = link[0].slice(0, link[0].indexOf("."))
inst.#boardId = link[2]
inst.#isThread = post.classList.contains("op")
inst.#isReply = !inst.#isThread
inst.#subject = intro.querySelector(".subject")?.innerText ?? null
inst.#name = intro.querySelector(".name")?.innerText ?? null
inst.#email = intro.querySelector(".email")?.href.slice(7) ?? null
inst.#flag = intro.querySelector(".flag")?.src.split("/").reverse()[0].slice(0, -4) ?? null
inst.#capcode = intro.querySelector(".capcode")?.innerText ?? null
inst.#ip = intro.querySelector(".ip-link")?.innerText ?? null
inst.#createdAt = new Date(intro.querySelector("time[datetime]").dateTime ?? NaN)
inst.#isSticky = !!intro.querySelector("i.fa-thumb-tack")
inst.#isLocked = !!intro.querySelector("i.fa-lock")
return inst
} }
static "from" (post) {
assert.ok(post.classList.contains("post"), "Arty must be expected Element.");
const inst = new this();
const intro = post.querySelector(".intro");
const link = intro.querySelector(".post_no:not([id])").href.split("/").reverse();
inst._postId = link[0].slice(link[0].indexOf("#q") + 2);
inst._threadId = link[0].slice(0, link[0].indexOf("."));
inst._boardId = link[2];
inst._isThread = post.classList.contains("op");
inst._isReply = !inst._isThread;
inst._subject = cont(intro.querySelector(".subject"), x => x.innerText);
inst._name = cont(intro.querySelector(".name"), x => x.innerText);
inst._email = cont(intro.querySelector(".email"), x => x.href.slice(7));
inst._flag = cont(intro.querySelector(".flag"), x => x.src.split("/").reverse()[0].slice(0, -4));
inst._capcode = cont(intro.querySelector(".capcode"), x => x.innerText);
inst._ip = cont(intro.querySelector(".ip-link"), x => x.innerText);
inst._createdAt = new Date(intro.querySelector("time[datetime]").dateTime || NaN);
inst._isSticky = !!intro.querySelector("i.fa-thumb-tack");
inst._isLocked = !!intro.querySelector("i.fa-lock");
return inst;
}
"getParent" () { return this._parent; }
"__setParent" (inst) { return this._parent = inst; }
"getBoardId" () { return this._boardId; }
"getThreadId" () { return this._threadId; }
"getPostId" () { return this._postId; }
"getHref" () { return `/${this.boardId}/res/${this.threadId}.html#q${this.postId}`; }
"getName" () { return this._name; }
"getEmail" () { return this._email; }
"getIP" () { return this._ip; }
"getCapcode" () { return this._capcode; }
"getSubject" () { return this._subject; }
"getCreatedAt" () { return this._createdAt; }
"isSticky" () { return this._isSticky; }
"isLocked" () { return this._isLocked; }
"isThread" () { return this._isThread; }
"isReply" () { return this._isReply; }
"is" (info) {
assert.ok(info, "Must be LCNPost.")
return this.getBoardId() == info.getBoardId() && this.getPostId() == info.getPostId()
}
// "getParent" () { return this.#parent; }
// "__setParent" (inst) { return this.#parent = inst; }
//
// "getBoardId" () { return this.#boardId; }
// "getThreadId" () { return this.#threadId; }
// "getPostId" () { return this.#postId; }
// "getHref" () { return `/${this.boardId}/res/${this.threadId}.html#q${this.postId}`; }
//
// "getName" () { return this.#name; }
// "getEmail" () { return this.#email; }
// "getIP" () { return this.#ip; }
// "getCapcode" () { return this.#capcode; }
// "getSubject" () { return this.#subject; }
// "getCreatedAt" () { return this.#createdAt; }
//
// "isSticky" () { return this.#isSticky; }
// "isLocked" () { return this.#isLocked; }
// "isThread" () { return this.#isThread; }
// "isReply" () { return this.#isReply; }
//
// "is" (info) {
// assert.ok(info, "Must be LCNPost.")
// return this.getBoardId() == info.getBoardId() && this.getPostId() == info.getPostId()
// }
//
} }
LCNPostInfo.nodeAttrib = "$LCNPostInfo"; LCNPostInfo.nodeAttrib = "$LCNPostInfo";
LCNPostInfo.selector = ".post:not(.grid-li)"; LCNPostInfo.selector = ".post:not(.grid-li)";
// globalThis.LCNPost = class LCNPost { globalThis.LCNPost = class LCNPost {
//
// static nodeAttrib = "$LCNPost"; static "assign" (post) {
// static selector = ".post:not(.grid-li)"; return post[this.nodeAttrib] || (post[this.nodeAttrib] = this.from(post));
// #parent = null; }
// #post = null;
// #info = null; static "from" (post) { return new this(post); }
// #ipLink = null;
// #controls = null; constructor (post) {
// #customControlsSeperatorNode = null; this._parent = null;
// this._post = null;
// static "assign" (post) { return post[this.nodeAttrib] ?? (post[this.nodeAttrib] = this.from(post)); } this._info = null;
// static "from" (post) { return new this(post); } this._ipLink = null;
// this._controls = null;
// "constructor" (post) { this._customControlsSeperatorNode = null;
// assert.ok(post.classList.contains("post"), "Arty must be expected Element.")
// const intro = post.querySelector(".intro") assert.ok(post.classList.contains("post"), "Arty must be expected Element.");
// this.#post = post const intro = post.querySelector(".intro");
// this.#info = LCNPostInfo.assign(post) this._post = post;
// this.#ipLink = intro.querySelector(".ip-link") this._info = LCNPostInfo.assign(post);
// this.#controls = Array.prototype.at.apply(post.querySelectorAll(".controls"), [ -1 ]) this._ipLink = intro.querySelector(".ip-link");
// this._controls = Array.prototype.at.apply(post.querySelectorAll(".controls"), [ -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);
// } }
//
// "jQuery" () { return $(this.#post); }
// "trigger" (event_id, data=null) { $(this.#post).trigger(event_id, [ data ]); } "jQuery" () { return $(this._post); }
// "trigger" (event_id, data=null) { $(this._post).trigger(event_id, [ data ]); }
// "getElement" () { return this.#post; }
// "getInfo" () { return this.#info; } "getElement" () { return this._post; }
// "getInfo" () { return this._info; }
// "getIPLink" () { return this.#ipLink; }
// "setIP" (ip) { this.#ipLink.innerText = ip; } "getIPLink" () { return this._ipLink; }
// "setIP" (ip) { this._ipLink.innerText = ip; }
// "getParent" () { return this.#parent; }
// "__setParent" (inst) { return this.#parent = inst; } "getParent" () { return this._parent; }
// "__setParent" (inst) { return this._parent = inst; }
// static #NBSP = String.fromCharCode(160);
// "addCustomControl" (obj) { "addCustomControl" (obj) {
// if (LCNSite.INSTANCE.isModerator()) { if (LCNSite.INSTANCE.isModerator()) {
// const link = document.createElement("a") const link = document.createElement("a")
// link.innerText = `[${obj.btn}]` link.innerText = `[${obj.btn}]`
// link.title = obj.tooltip link.title = obj.tooltip
//
// if (typeof obj.href == "string") { if (typeof obj.href == "string") {
// link.href = obj.href link.href = obj.href
// link.referrerPolicy = "no-referrer" link.referrerPolicy = "no-referrer"
// } else if (obj.onClick != undefined) { } else if (obj.onClick != undefined) {
// link.style.cursor = "pointer" link.style.cursor = "pointer"
// link.addEventListener("click", e => { e.preventDefault(); obj.onClick(this); }) link.addEventListener("click", e => { e.preventDefault(); obj.onClick(this); })
// } }
//
// if (this.#customControlsSeperatorNode == null) { if (this._customControlsSeperatorNode == null) {
// this.#controls.insertBefore(this.#customControlsSeperatorNode = new Text(`${this.constructor.#NBSP}-${this.constructor.#NBSP}`), this.#controls.firstElementChild) this._controls.insertBefore(this._customControlsSeperatorNode = new Text(`${this.constructor.NBSP}-${this.constructor.NBSP}`), this._controls.firstElementChild)
// } else { } else {
// this.#controls.insertBefore(new Text(this.constructor.#NBSP), this.#customControlsSeperatorNode) this._controls.insertBefore(new Text(this.constructor.NBSP), this._customControlsSeperatorNode)
// } }
//
// this.#controls.insertBefore(link, this.#customControlsSeperatorNode) this._controls.insertBefore(link, this._customControlsSeperatorNode)
// } }
// } }
//
// } }
//
// globalThis.LCNThread = class LCNThread { globalThis.LCNPost.nodeAttrib = "$LCNPost";
// globalThis.LCNPost.selector = ".post:not(.grid-li)";
// static nodeAttrib = "$LCNThread"; globalThis.LCNPost. NBSP = String.fromCharCode(160);
// static selector = ".thread:not(.grid-li)";
// #element = null; globalThis.LCNThread = class LCNThread {
// #parent = null;
// #op = null; static "assign" (thread) {
// return thread[this.nodeAttrib] || (thread[this.nodeAttrib] = this.from(thread));
// static "assign" (thread) { return thread[this.nodeAttrib] ?? (thread[this.nodeAttrib] = this.from(thread)); } }
// static "from" (thread) { return new this(thread); }
// static "from" (thread) { return new this(thread); }
// "constructor" (thread) {
// assert.ok(thread.classList.contains("thread"), "Arty must be expected Element.") constructor (thread) {
// this.#element = thread this._element = null;
// this.#op = LCNPost.assign(this.#element.querySelector(".post.op")) this._parent = null;
// this._op = null;
// //assert.equal(this.#op.getParent(), null, "Op should not have parent.") assert.ok(thread.classList.contains("thread"), "Arty must be expected Element.")
// this.#op.__setParent(this) this._element = thread
// } this._op = LCNPost.assign(this._element.querySelector(".post.op"))
// assert.equal(this._op.getParent(), null, "Op should not have parent.")
// "getElement" () { return this.#element; } this._op.__setParent(this)
// "getContent" () { return this.#op; } }
// "getPosts" () { return Array.prototype.map.apply(this.#element.querySelectorAll(".post"), [ el => LCNPost.assign(el) ]); }
// "getReplies" () { return Array.prototype.map.apply(this.#element.querySelectorAll(".post:not(.op)"), [ el => LCNPost.assign(el) ]); } "getElement" () { return this._element; }
// "getContent" () { return this._op; }
// "getParent" () { return this.#parent; } "getPosts" () { return Array.prototype.map.apply(this._element.querySelectorAll(".post"), [ el => LCNPost.assign(el) ]); }
// "__setParent" (inst) { return this.#parent = inst; } "getReplies" () { return Array.prototype.map.apply(this._element.querySelectorAll(".post:not(.op)"), [ el => LCNPost.assign(el) ]); }
// }
// "getParent" () { return this._parent; }
// "__setParent" (inst) { return this._parent = inst; }
// globalThis.LCNPostContainer = class LCNPostContainer { }
//
// static nodeAttrib = "$LCNPostContainer"; globalThis.LCNThread.nodeAttrib = "$LCNThread";
// static selector = ".postcontainer"; globalThis.LCNThread.selector = ".thread:not(.grid-li)";
// #parent = null;
// #element = null;
// #content = null; globalThis.LCNPostContainer = class LCNPostContainer {
// #postId = null;
// #boardId = null; static "assign" (container) { return container[this.nodeAttrib] || (container[this.nodeAttrib] = this.from(container)); }
// static "from" (container) { return new this(container); }
// static "assign" (container) { return container[this.nodeAttrib] ?? (container[this.nodeAttrib] = this.from(container)); }
// static "from" (container) { return new this(container); } constructor (container) {
// this._parent = null;
// "constructor" (container) { this._element = null;
// assert.ok(container.classList.contains("postcontainer"), "Arty must be expected Element.") this._content = null;
// const child = container.querySelector(".thread, .post") this._postId = null;
// this.#element = container this._boardId = null;
// this.#content = child.classList.contains("thread") ? LCNThread.assign(child) : LCNPost.assign(child)
// this.#boardId = container.dataset.board assert.ok(container.classList.contains("postcontainer"), "Arty must be expected Element.")
// this.#postId = container.id.slice(2) const child = container.querySelector(".thread, .post")
// this._element = container
// assert.equal(this.#content.getParent(), null, "Content should not have parent.") this._content = child.classList.contains("thread") ? LCNThread.assign(child) : LCNPost.assign(child)
// this.#content.__setParent(this) this._boardId = container.dataset.board
// } this._postId = container.id.slice(2)
//
// "getElement" () { return this.#element; } assert.equal(this._content.getParent(), null, "Content should not have parent.")
// "getContent" () { return this.#content; } this._content.__setParent(this)
// "getBoardId" () { return this.#boardId; } }
// "getPostId" () { return this.#postId; }
// "getElement" () { return this._element; }
// "getParent" () { return this.#parent; } "getContent" () { return this._content; }
// "__setParent" (inst) { return this.#parent = inst; } "getBoardId" () { return this._boardId; }
// "getPostId" () { return this._postId; }
// }
// "getParent" () { return this._parent; }
// globalThis.LCNPostWrapper = class LCNPostWrapper { "__setParent" (inst) { return this._parent = inst; }
//
// static nodeAttrib = "$LCNPostWrapper"; }
// static selector = ".post-wrapper";
// #wrapper = null; globalThis.LCNPostContainer.nodeAttrib = "$LCNPostContainer";
// #eitaLink = null; globalThis.LCNPostContainer.selector = ".postcontainer";
// #eitaId = null;
// #eitaHref = null
// #content = null; globalThis.LCNPostWrapper = class LCNPostWrapper {
//
// static "assign" (wrapper) { return wrapper[this.nodeAttrib] ?? (wrapper[this.nodeAttrib] = this.from(wrapper)); } static "assign" (wrapper) { return wrapper[this.nodeAttrib] || (wrapper[this.nodeAttrib] = this.from(wrapper)); }
// static "from" (wrapper) { return new this(wrapper); } static "from" (wrapper) { return new this(wrapper); }
//
// "constructor" (wrapper) { constructor (wrapper) {
// assert.ok(wrapper.classList.contains("post-wrapper"), "Arty must be expected Element.") this._wrapper = null;
// this.#wrapper = wrapper this._eitaLink = null;
// this.#eitaLink = wrapper.querySelector(".eita-link") this._eitaId = null;
// this.#eitaId = this.#eitaLink.id this._eitaHref = null
// this.#eitaHref = this.#eitaLink.href this._content = null;
// void Array.prototype.find.apply(wrapper.children, [
// el => { assert.ok(wrapper.classList.contains("post-wrapper"), "Arty must be expected Element.")
// if (el.classList.contains("thread")) { this._wrapper = wrapper
// return this.#content = LCNThread.assign(el) this._eitaLink = wrapper.querySelector(".eita-link")
// } else if (el.classList.contains("postcontainer")) { this._eitaId = this._eitaLink.id
// return this.#content = LCNPostContainer.assign(el) this._eitaHref = this._eitaLink.href
// }
// } void Array.prototype.find.apply(wrapper.children, [
// ]) el => {
// if (el.classList.contains("thread")) {
// assert.ok(this.#content, "Wrapper should contain content.") return this._content = LCNThread.assign(el)
// assert.equal(this.#content.getParent(), null, "Content should not have parent.") } else if (el.classList.contains("postcontainer")) {
// this.#content.__setParent(this) return this._content = LCNPostContainer.assign(el)
// } }
// }
// "getPost" () { ])
// const post = this.getContent().getContent()
// assert.ok(post instanceof LCNPost, "Post should be LCNPost.") assert.ok(this._content, "Wrapper should contain content.")
// return post assert.equal(this._content.getParent(), null, "Content should not have parent.")
// } this._content.__setParent(this)
// }
// "getElement" () { return this.#wrapper; }
// "getContent" () { return this.#content; } "getPost" () {
// "getEitaId" () { return this.#eitaId; } const post = this.getContent().getContent()
// "getEitaHref" () { return this.#eitaHref; } assert.ok(post instanceof LCNPost, "Post should be LCNPost.")
// "getEitaLink" () { return this.#eitaLink; } return post
// }
// }
// "getElement" () { return this._wrapper; }
// globalThis.LCNSetting = class LCNSetting { "getContent" () { return this._content; }
// #id = null; "getEitaId" () { return this._eitaId; }
// #eventId = null; "getEitaHref" () { return this._eitaHref; }
// #label = null; "getEitaLink" () { return this._eitaLink; }
// #value = null; }
// #valueDefault = null;
// globalThis.LCNPostWrapper.nodeAttrib = "$LCNPostWrapper";
// static "build" (id) { return new this(id); } globalThis.LCNPostWrapper.selector = ".post-wrapper";
//
// "constructor" (id) {
// this.#id = id; globalThis.LCNSetting = class LCNSetting {
// this.#eventId = `lcnsetting::${this.#id}` static "build" (id) { return new this(id); }
// }
// constructor (id) {
// #getValue () { this._id = null;
// const v = localStorage.getItem(this.#id) this._eventId = null;
// if (v != null) { this._label = null;
// return this.__builtinValueImporter(v) this._value = null;
// } else { this._valueDefault = null;
// return this.#valueDefault
// } this._id = id;
// } this._eventId = `lcnsetting::${this._id}`
// }
// "getValue" () { return this.#value ?? (this.#value = this.#getValue()); }
// "setValue" (v) { "_getValue" () {
// if (this.#value !== v) { const v = localStorage.getItem(this._id)
// this.#value = v if (v != null) {
// localStorage.setItem(this.#id, this.__builtinValueExporter(this.#value)) return this.__builtinValueImporter(v)
// setTimeout(() => $(document).trigger(`${this.#eventId}::change`, [ v, this ]), 1) } else {
// } return this._valueDefault
// } }
// }
// "getLabel" () { return this.#label; }
// "setLabel" (label) { this.#label = label; return this; } "getValue" () { return this._value || (this._value = this._getValue()); }
// "setValue" (v) {
// "getDefaultValue" () { return this.#valueDefault; } if (this._value !== v) {
// "setDefaultValue" (vd) { this.#valueDefault = vd; return this; } this._value = v
// localStorage.setItem(this._id, this.__builtinValueExporter(this._value))
// "onChange" (fn) { $(document).on(`${this.#eventId}::change`, (_,v,i) => fn(v, i)); } setTimeout(() => $(document).trigger(`${this._eventId}::change`, [ v, this ]), 1)
// __setIdPrefix (prefix) { this.#id = `${prefix}_${this.#id}`; } }
// } }
//
// globalThis.LCNToggleSetting = class LCNToggleSetting extends LCNSetting { "getLabel" () { return this._label; }
// __builtinValueImporter (v) { return v == "1"; } "setLabel" (label) { this._label = label; return this; }
// __builtinValueExporter (v) { return v ? "1" : ""; }
// __builtinDOMConstructor () { "getDefaultValue" () { return this._valueDefault; }
// const div = document.createElement("div") "setDefaultValue" (vd) { this._valueDefault = vd; return this; }
// const chk = document.createElement("input")
// const txt = document.createElement("label") "onChange" (fn) { $(document).on(`${this._eventId}::change`, (_,v,i) => fn(v, i)); }
// txt.innerText = this.getLabel() __setIdPrefix (prefix) { this._id = `${prefix}_${this._id}`; }
// chk.type = "checkbox" }
// chk.checked = this.getValue()
// chk.addEventListener("click", e => { globalThis.LCNToggleSetting = class LCNToggleSetting extends LCNSetting {
// e.preventDefault(); __builtinValueImporter (v) { return v == "1"; }
// this.setValue(!this.getValue()) __builtinValueExporter (v) { return v ? "1" : ""; }
// }) __builtinDOMConstructor () {
// this.onChange(v => chk.checked = v) const div = document.createElement("div")
// const chk = document.createElement("input")
// div.appendChild(chk) const lbl = document.createElement("label")
// div.appendChild(txt) const id = `${this._id}_input`
// return div lbl.htmlFor = id
// } lbl.innerText = this.getLabel()
// } chk.id = id
// chk.type = "checkbox"
// globalThis.LCNSettingsSubcategory = class LCNSettingsSubcategory { chk.checked = this.getValue()
// chk.addEventListener("click", e => {
// #tab_id = null; e.preventDefault();
// #id = null; this.setValue(!this.getValue())
// })
// #fieldset = null; this.onChange(v => chk.checked = v)
// #legend = null;
// #label = null; div.appendChild(chk)
// div.appendChild(lbl)
// static "for" (tab_id, id) { return div
// const domid = `lcnssc_${tab_id}_${id}` }
// const inst = document.getElementById(domid)?.$LCNSettingsSubcategory }
// if (inst == null) {
// const fieldset = document.createElement("fieldset") globalThis.LCNSettingsSubcategory = class LCNSettingsSubcategory {
// const legend = document.createElement("legend")
// fieldset.id = domid static "for" (tab_id, id) {
// fieldset.appendChild(legend) const domid = `lcnssc_${tab_id}_${id}`
// const inst = cont(document.getElementById(domid), x => x.$LCNSettingsSubcategory)
// // XXX: extend_tab only takes a string so this hacky workaround is used to let us use the regular dom api
// Options.extend_tab(tab_id, `<div id="__${domid}" hidden></div>`) if (inst == null) {
// const div = document.getElementById(`__${domid}`)?.parentElement const fieldset = document.createElement("fieldset")
// assert.ok(div) const legend = document.createElement("legend")
// fieldset.id = domid
// div.replaceChildren(fieldset) fieldset.appendChild(legend)
// return new this(tab_id, id, fieldset)
// } else { // XXX: extend_tab only takes a string so this hacky workaround is used to let us use the regular dom api
// return inst Options.extend_tab(tab_id, `<div id="__${domid}" hidden></div>`)
// } const div = cont(document.getElementById(`__${domid}`), x => x.parentElement)
// } assert.ok(div)
//
// "constructor" (tab_id, id, fieldset) { div.replaceChildren(fieldset)
// this.#tab_id = tab_id return new this(tab_id, id, fieldset)
// this.#id = id } else {
// this.#fieldset = fieldset return inst
// this.#legend = this.#fieldset.querySelector("legend") }
// this.#fieldset.$LCNSettingsSubcategory = this }
// }
// constructor (tab_id, id, fieldset) {
// "getLabel" () { return this.#label; } this._tab_id = tab_id
// "setLabel" (label) { this.#legend.innerText = this.#label = label; return this; } this._id = id
// "addSetting" (setting) { this._fieldset = fieldset
// assert.ok(setting instanceof LCNSetting) this._legend = this._fieldset.querySelector("legend")
// setting.__setIdPrefix(`lcnsetting_${this.#tab_id}_${this.#id}`) this._fieldset.$LCNSettingsSubcategory = this
// if (setting.__builtinDOMConstructor != null) { }
// const div = setting.__builtinDOMConstructor()
// div.classList.add("lcn-setting-entry") "getLabel" () { return this._label; }
// this.#fieldset.appendChild(div) "setLabel" (label) { this._legend.innerText = this._label = label; return this; }
// } "addSetting" (setting) {
// assert.ok(setting instanceof LCNSetting)
// return this setting.__setIdPrefix(`lcnsetting_${this._tab_id}_${this._id}`)
// } if (setting.__builtinDOMConstructor != null) {
// const div = setting.__builtinDOMConstructor()
// } div.classList.add("lcn-setting-entry")
// this._fieldset.appendChild(div)
// $().ready(() => { }
// LCNSite.INSTANCE = new LCNSite();
// return this
// for (const clazz of [ LCNPost, LCNPostInfo, LCNThread, LCNPostContainer, LCNPostWrapper ]) { }
// clazz.allNodes = (node=document) => node.querySelectorAll(clazz.selector)
// clazz.all = (node=document) => Array.prototype.map.apply(clazz.allNodes(node), [ elem => clazz.assign(elem) ]); }
// clazz.clear = (node=document) => Array.prototype.forEach.apply(clazz.allNodes(node), [ elem => elem[clazz.nodeAttrib] = null ])
// clazz.forEach = (fn, node=document) => clazz.allNodes(node).forEach(elem => fn(clazz.assign(elem))) $().ready(() => {
// clazz.filter = (fn, node=document) => clazz.all(node).filter(fn) LCNSite.INSTANCE = new LCNSite();
// clazz.find = fn => clazz.all().find(fn)
// clazz.first = (node=document) => clazz.assign(node.querySelector(clazz.selector)) for (const clazz of [ LCNPost, LCNPostInfo, LCNThread, LCNPostContainer, LCNPostWrapper ]) {
// clazz.last = (node=document) => clazz.assign(Array.prototype.at.apply(clazz.allNodes(node), [ -1 ])) clazz.allNodes = (node=document) => node.querySelectorAll(clazz.selector)
// } clazz.all = (node=document) => Array.prototype.map.apply(clazz.allNodes(node), [ elem => clazz.assign(elem) ]);
// clazz.clear = (node=document) => Array.prototype.forEach.apply(clazz.allNodes(node), [ elem => elem[clazz.nodeAttrib] = null ])
// // XXX: May be a cleaner way to do this but this should be fine for now. clazz.forEach = (fn, node=document) => clazz.allNodes(node).forEach(elem => fn(clazz.assign(elem)))
// for (const clazz of [ LCNPostContainer, LCNPostWrapper, LCNThread, LCNPost ]) { void clazz.all(); } clazz.filter = (fn, node=document) => clazz.all(node).filter(fn)
// $(document).on("new_post", (e, post) => { clazz.find = fn => clazz.all().find(fn)
// if (LCNSite.INSTANCE.isModRecentsPage()) { clazz.first = (node=document) => { return clazz.assign(node.querySelector(clazz.selector)); }
// void LCNPostWrapper.all() clazz.last = (node=document) => clazz.assign(Array.prototype.at.apply(clazz.allNodes(node), [ -1 ]))
// } else { }
// void LCNPostContainer.all()
// } // XXX: May be a cleaner way to do this but this should be fine for now.
// }) for (const clazz of [ LCNPostContainer, LCNPostWrapper, LCNThread, LCNPost ]) { void clazz.all(); }
// $(document).on("new_post", (e, post) => {
// $(window).on("focus", () => LCNSite.INSTANCE.clearUnseen()) if (LCNSite.INSTANCE.isModRecentsPage()) {
// $(document.body).on("mousemove", () => LCNSite.INSTANCE.clearUnseen()) void LCNPostWrapper.all()
// }) } else {
void LCNPostContainer.all()
}
})
$(window).on("focus", () => LCNSite.INSTANCE.clearUnseen())
$(document.body).on("mousemove", () => LCNSite.INSTANCE.clearUnseen())
})

View File

@ -4,14 +4,13 @@
*/ */
$().ready(() => { $().ready(() => {
const kIsEnabled = LCNToggleSetting.build("enabled") const kIsEnabled = LCNToggleSetting.build("enabled")
//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(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))*/;
@ -30,7 +29,7 @@ $().ready(() => {
const abortable = LCNSite.createAbortable() const abortable = LCNSite.createAbortable()
const threadStatsItems = [] const threadStatsItems = []
const updateDOMStatus = () => { const updateDOMStatus = () => {
const text = threadState ?? (secondsCounter >= 0 ? `${secondsCounter}s` : "…") const text = threadState || (secondsCounter >= 0 ? `${secondsCounter}s` : "…")
threadUpdateStatus.innerText = text threadUpdateStatus.innerText = text
} }
@ -59,7 +58,7 @@ $().ready(() => {
} }
const findMissingReplies = (thread_op, thread_dom, thread_latest) => { const findMissingReplies = (thread_op, thread_dom, thread_latest) => {
const lastPostTs = (thread_dom.at(-1)?.getInfo() ?? thread_op).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()) {
@ -129,6 +128,7 @@ $().ready(() => {
if (threadState == null) { if (threadState == null) {
if (secondsCounter < 0) { if (secondsCounter < 0) {
const thread = LCNThread.first() const thread = LCNThread.first()
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)) {
@ -149,10 +149,11 @@ $().ready(() => {
onTickId = setTimeout(onTickFn, 1000) onTickId = setTimeout(onTickFn, 1000)
} }
} }
$(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")
@ -233,7 +234,7 @@ $().ready(() => {
$(document).trigger("thread_manual_refresh") $(document).trigger("thread_manual_refresh")
} else { } else {
floaterLinkBox?.remove() cont(floaterLinkBox, x => x.remove())
floaterLinkBox = null floaterLinkBox = null
statReplies = null statReplies = null
statFiles = null statFiles = null

View File

@ -3,6 +3,54 @@
* @author jonsmy * @author jonsmy
*/ */
function cont(value_to_test, fn) {
if (value_to_test != null) {
return fn(value_to_test);
} else {
return null;
}
}
function text(s) {
return document.createTextNode(s);
}
function prepend(elem, children) {
var child = elem.firstChild;
if (child) {
elem.insertBefore(children, child);
} else {
elem.appendChild(children);
}
}
function _log() {
for (var arg of arguments) {
if (arg == null) {
continue;
}
var pre = document.createElement('pre');
pre.appendChild(text(arg.toString()));
document.body.appendChild(pre);
try {
prepend(document.body, pre);
} catch (e) {
var pre = document.createElement('pre');
pre.appendChild(text(e.toString()));
document.body.appendChild(pre);
}
}
}
var console = {
log: _log,
error: _log
};
const assert = { const assert = {
"equal": (actual, expected, message="No message set") => { "equal": (actual, expected, message="No message set") => {
if (actual !== expected) { if (actual !== expected) {
@ -41,3 +89,25 @@ if (AbortSignal.any == null) {
return controller.signal; return controller.signal;
} }
} }
// polyfill for replaceChildren
if( Node.prototype.replaceChildren === undefined) {
Node.prototype.replaceChildren = function(addNodes) {
while(this.lastChild) {
this.removeChild(this.lastChild);
}
if (addNodes !== undefined) {
this.append(addNodes);
}
}
}
if (Array.prototype.at === undefined) {
Array.prototype.at = function(index) {
if (index >= 0) {
return this[index];
} else {
return this[this.length + index];
}
};
}