Compare commits

..

No commits in common. "c8f460aa9d9d4bfcadea1fead91e50e5433e5ccb" and "96eb7986845c8a29c309192b0e342f98e67ee276" have entirely different histories.

3 changed files with 382 additions and 468 deletions

View File

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

View File

@ -4,13 +4,14 @@
*/ */
$().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))*/;
@ -29,7 +30,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
} }
@ -58,7 +59,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).getCreatedAt().getTime() const lastPostTs = (thread_dom.at(-1)?.getInfo() ?? thread_op).getCreatedAt().getTime()
const missing = [] const missing = []
for (const pc of thread_latest.reverse()) { for (const pc of thread_latest.reverse()) {
@ -128,7 +129,6 @@ $().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,11 +149,10 @@ $().ready(() => {
onTickId = setTimeout(onTickFn, 1000) onTickId = setTimeout(onTickFn, 1000)
} }
} }
$(document).on("ajax_after_post", (_, xhr_body) => { $(document).on("ajax_after_post", (_, xhr_body) => {
if (xhr_body != null) { if (kIsEnabled.getValue() && 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")
@ -234,7 +233,7 @@ $().ready(() => {
$(document).trigger("thread_manual_refresh") $(document).trigger("thread_manual_refresh")
} else { } else {
cont(floaterLinkBox, x => x.remove()) floaterLinkBox?.remove()
floaterLinkBox = null floaterLinkBox = null
statReplies = null statReplies = null
statFiles = null statFiles = null

View File

@ -3,54 +3,6 @@
* @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) {
@ -89,25 +41,3 @@ 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];
}
};
}