Compare commits

..

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

4 changed files with 488 additions and 500 deletions

View File

@ -4,6 +4,7 @@
*/ */
globalThis.LCNSite = class LCNSite { globalThis.LCNSite = class LCNSite {
static INSTANCE = null;
static "createAbortable" () { static "createAbortable" () {
const obj = { "abort": null, "controller": null, "signal": null } const obj = { "abort": null, "controller": null, "signal": null }
@ -31,62 +32,54 @@ globalThis.LCNSite = class LCNSite {
} }
return null return null
};
static "constructor" () {
this._isModerator = document.body.classList.contains("is-moderator");
this._isThreadPage = document.body.classList.contains("active-thread");
this._isBoardPage = document.body.classList.contains("active-board");
this._isCatalogPage = document.body.classList.contains("active-catalog");
this._isModPage = location.pathname == "/mod.php";
this._isModRecentsPage = this._isModPage && (location.search == "?/recent" || location.search.startsWith("?/recent/"));
this._isModReportsPage = this._isModPage && (location.search == "?/reports" || location.search.startsWith("?/reports/"));
this._isModLogPage = this._isModPage && (location.search == "?/log" || location.search.startsWith("?/log/"));
this._unseen = 0;
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._generatedStyle = null;
} }
"isModerator" () { return this._isModerator; } #isModerator = document.body.classList.contains("is-moderator");
"isThreadPage" () { return this._isThreadPage; } #isThreadPage = document.body.classList.contains("active-thread");
"isBoardPage" () { return this._isBoardPage; } #isBoardPage = document.body.classList.contains("active-board");
"isCatalogPage" () { return this._isCatalogPage; } #isCatalogPage = document.body.classList.contains("active-catalog");
"isModPage" () { return this._isModPage; } #isModPage = location.pathname == "/mod.php";
"isModRecentsPage" () { return this._isModRecentsPage; } #isModRecentsPage = this.#isModPage && (location.search == "?/recent" || location.search.startsWith("?/recent/"));
"isModReportsPage" () { return this._isModReportsPage; } #isModReportsPage = this.#isModPage && (location.search == "?/reports" || location.search.startsWith("?/reports/"));
"isModLogPage" () { return this._isModLogPage; } #isModLogPage = this.#isModPage && (location.search == "?/log" || location.search.startsWith("?/log/"));
"getUnseen" () { return this._unseen; } "isModerator" () { return this.#isModerator; }
"clearUnseen" () { if (this._unseen != 0) { this.setUnseen(0); } } "isThreadPage" () { return this.#isThreadPage; }
"isBoardPage" () { return this.#isBoardPage; }
"isCatalogPage" () { return this.#isCatalogPage; }
"isModPage" () { return this.#isModPage; }
"isModRecentsPage" () { return this.#isModRecentsPage; }
"isModReportsPage" () { return this.#isModReportsPage; }
"isModLogPage" () { return this.#isModLogPage; }
#unseen = 0;
"getUnseen" () { return this.#unseen; }
"clearUnseen" () { if (this.#unseen != 0) { this.setUnseen(0); } }
"setUnseen" (int) { "setUnseen" (int) {
const bool = !!int const bool = !!int
if (bool != !!this._unseen) { if (bool != !!this.#unseen) {
this.setFaviconType(bool ? "reply" : null) this.setFaviconType(bool ? "reply" : null)
} }
this._unseen = int this.#unseen = int
this._doTitleUpdate() this.#doTitleUpdate()
} }
"getTitle" () { return this._pageTitle; } #pageTitle = document.title;
"setTitle" (title) { this._pageTitle = title; this._doTitleUpdate(); } "getTitle" () { return this.#pageTitle; }
"setTitle" (title) { this.#pageTitle = title; this.#doTitleUpdate(); }
#doTitleUpdate () { document.title = (this.#unseen > 0 ? `(${this.#unseen}) ` : "") + this.#pageTitle; }
#favicon = document.querySelector("head > link[rel=\"shortcut icon\"]");
"setFaviconType" (type=null) { "setFaviconType" (type=null) {
if (this._favicon == null) { if (this.#favicon == null) {
this._favicon = document.createElement("link") this.#favicon = document.createElement("link")
this._favicon.rel = "shortcut icon" this.#favicon.rel = "shortcut icon"
document.head.appendChild(this._favicon) document.head.appendChild(this.#favicon)
} }
this._favicon.href = `/favicon${type ? "-" + type : ""}.ico` this.#favicon.href = `/favicon${type ? "-" + type : ""}.ico`
} }
"getFloaterLContainer" () { return document.getElementById("bar-bottom-l"); } "getFloaterLContainer" () { return document.getElementById("bar-bottom-l"); }
@ -94,39 +87,38 @@ globalThis.LCNSite = class LCNSite {
"getThreadStatsLContainer" () { return document.getElementById("lcn-threadstats-l"); } "getThreadStatsLContainer" () { return document.getElementById("lcn-threadstats-l"); }
"getThreadStatsRContainer" () { return document.getElementById("lcn-threadstats-r"); } "getThreadStatsRContainer" () { return document.getElementById("lcn-threadstats-r"); }
#generatedStyle = null;
"writeCSSStyle" (origin, stylesheet) { "writeCSSStyle" (origin, stylesheet) {
if (this._generatedStyle == null && (this._generatedStyle = document.querySelector("head > style.generated-css")) == null) { if (this.#generatedStyle == null && (this.#generatedStyle = document.querySelector("head > style.generated-css")) == null) {
this._generatedStyle = document.createElement("style") this.#generatedStyle = document.createElement("style")
this._generatedStyle.classList.add("generated-css") this.#generatedStyle.classList.add("generated-css")
document.head.appendChild(this._generatedStyle) document.head.appendChild(this.#generatedStyle)
} }
this._generatedStyle.textContent += `${this._generatedStyle.textContent.length ? "\n\n" : ""}/*** Generated by ${origin} ***/\n${stylesheet}` this.#generatedStyle.textContent += `${this.#generatedStyle.textContent.length ? "\n\n" : ""}/*** Generated by ${origin} ***/\n${stylesheet}`
} }
} }
LCNSite.INSTANCE = null;
globalThis.LCNPostInfo = class LCNPostInfo { globalThis.LCNPostInfo = class LCNPostInfo {
static "constructor" () { static nodeAttrib = "$LCNPostInfo";
this._boardId = null; static selector = ".post:not(.grid-li)";
this._threadId = null; #boardId = null;
this._postId = null; #threadId = null;
this._name = null; #postId = null;
this._email = null; #name = null;
this._capcode = null; #email = null;
this._flag = null; #capcode = null;
this._ip = null; #flag = null;
this._subject = null; #ip = null;
this._createdAt = null; #subject = null;
this._parent = null; #createdAt = null;
this._isThread = false;
this._isReply = false;
this._isLocked = false;
this._isSticky = false;
}
#parent = null;
#isThread = false;
#isReply = false;
#isLocked = false;
#isSticky = false;
static "assign" (post) { return post[this.nodeAttrib] ?? (post[this.nodeAttrib] = this.from(post)); } static "assign" (post) { return post[this.nodeAttrib] ?? (post[this.nodeAttrib] = this.from(post)); }
static "from" (post) { static "from" (post) {
@ -155,357 +147,353 @@ globalThis.LCNPostInfo = class LCNPostInfo {
return inst return inst
} }
"getParent" () { return this.#parent; }
"__setParent" (inst) { return this.#parent = inst; }
// "getParent" () { return this.#parent; } "getBoardId" () { return this.#boardId; }
// "__setParent" (inst) { return this.#parent = inst; } "getThreadId" () { return this.#threadId; }
// "getPostId" () { return this.#postId; }
// "getBoardId" () { return this.#boardId; } "getHref" () { return `/${this.boardId}/res/${this.threadId}.html#q${this.postId}`; }
// "getThreadId" () { return this.#threadId; }
// "getPostId" () { return this.#postId; } "getName" () { return this.#name; }
// "getHref" () { return `/${this.boardId}/res/${this.threadId}.html#q${this.postId}`; } "getEmail" () { return this.#email; }
// "getIP" () { return this.#ip; }
// "getName" () { return this.#name; } "getCapcode" () { return this.#capcode; }
// "getEmail" () { return this.#email; } "getSubject" () { return this.#subject; }
// "getIP" () { return this.#ip; } "getCreatedAt" () { return this.#createdAt; }
// "getCapcode" () { return this.#capcode; }
// "getSubject" () { return this.#subject; } "isSticky" () { return this.#isSticky; }
// "getCreatedAt" () { return this.#createdAt; } "isLocked" () { return this.#isLocked; }
// "isThread" () { return this.#isThread; }
// "isSticky" () { return this.#isSticky; } "isReply" () { return this.#isReply; }
// "isLocked" () { return this.#isLocked; }
// "isThread" () { return this.#isThread; } "is" (info) {
// "isReply" () { return this.#isReply; } assert.ok(info, "Must be LCNPost.")
// return this.getBoardId() == info.getBoardId() && this.getPostId() == info.getPostId()
// "is" (info) {
// assert.ok(info, "Must be LCNPost.")
// return this.getBoardId() == info.getBoardId() && this.getPostId() == info.getPostId()
// }
//
} }
LCNPostInfo.nodeAttrib = "$LCNPostInfo"; }
LCNPostInfo.selector = ".post:not(.grid-li)";
// globalThis.LCNPost = class LCNPost { globalThis.LCNPost = class LCNPost {
//
// static nodeAttrib = "$LCNPost"; static nodeAttrib = "$LCNPost";
// static selector = ".post:not(.grid-li)"; static selector = ".post:not(.grid-li)";
// #parent = null; #parent = null;
// #post = null; #post = null;
// #info = null; #info = null;
// #ipLink = null; #ipLink = null;
// #controls = null; #controls = null;
// #customControlsSeperatorNode = null; #customControlsSeperatorNode = null;
//
// static "assign" (post) { return post[this.nodeAttrib] ?? (post[this.nodeAttrib] = this.from(post)); } static "assign" (post) { return post[this.nodeAttrib] ?? (post[this.nodeAttrib] = this.from(post)); }
// static "from" (post) { return new this(post); } static "from" (post) { return new this(post); }
//
// "constructor" (post) { "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); 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.LCNThread = class LCNThread {
//
// static nodeAttrib = "$LCNThread"; static nodeAttrib = "$LCNThread";
// static selector = ".thread:not(.grid-li)"; static selector = ".thread:not(.grid-li)";
// #element = null; #element = null;
// #parent = null; #parent = null;
// #op = 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) { "constructor" (thread) {
// assert.ok(thread.classList.contains("thread"), "Arty must be expected Element.") assert.ok(thread.classList.contains("thread"), "Arty must be expected Element.")
// this.#element = thread this.#element = thread
// this.#op = LCNPost.assign(this.#element.querySelector(".post.op")) this.#op = LCNPost.assign(this.#element.querySelector(".post.op"))
//
// //assert.equal(this.#op.getParent(), null, "Op should not have parent.") //assert.equal(this.#op.getParent(), null, "Op should not have parent.")
// this.#op.__setParent(this) this.#op.__setParent(this)
// } }
//
// "getElement" () { return this.#element; } "getElement" () { return this.#element; }
// "getContent" () { return this.#op; } "getContent" () { return this.#op; }
// "getPosts" () { return Array.prototype.map.apply(this.#element.querySelectorAll(".post"), [ el => LCNPost.assign(el) ]); } "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) ]); } "getReplies" () { return Array.prototype.map.apply(this.#element.querySelectorAll(".post:not(.op)"), [ el => LCNPost.assign(el) ]); }
//
// "getParent" () { return this.#parent; } "getParent" () { return this.#parent; }
// "__setParent" (inst) { return this.#parent = inst; } "__setParent" (inst) { return this.#parent = inst; }
// } }
//
//
// globalThis.LCNPostContainer = class LCNPostContainer { globalThis.LCNPostContainer = class LCNPostContainer {
//
// static nodeAttrib = "$LCNPostContainer"; static nodeAttrib = "$LCNPostContainer";
// static selector = ".postcontainer"; static selector = ".postcontainer";
// #parent = null; #parent = null;
// #element = null; #element = null;
// #content = null; #content = null;
// #postId = null; #postId = null;
// #boardId = null; #boardId = null;
//
// static "assign" (container) { return container[this.nodeAttrib] ?? (container[this.nodeAttrib] = this.from(container)); } static "assign" (container) { return container[this.nodeAttrib] ?? (container[this.nodeAttrib] = this.from(container)); }
// static "from" (container) { return new this(container); } static "from" (container) { return new this(container); }
//
// "constructor" (container) { "constructor" (container) {
// assert.ok(container.classList.contains("postcontainer"), "Arty must be expected Element.") assert.ok(container.classList.contains("postcontainer"), "Arty must be expected Element.")
// const child = container.querySelector(".thread, .post") const child = container.querySelector(".thread, .post")
// this.#element = container this.#element = container
// this.#content = child.classList.contains("thread") ? LCNThread.assign(child) : LCNPost.assign(child) this.#content = child.classList.contains("thread") ? LCNThread.assign(child) : LCNPost.assign(child)
// this.#boardId = container.dataset.board this.#boardId = container.dataset.board
// this.#postId = container.id.slice(2) this.#postId = container.id.slice(2)
//
// assert.equal(this.#content.getParent(), null, "Content should not have parent.") assert.equal(this.#content.getParent(), null, "Content should not have parent.")
// this.#content.__setParent(this) this.#content.__setParent(this)
// } }
//
// "getElement" () { return this.#element; } "getElement" () { return this.#element; }
// "getContent" () { return this.#content; } "getContent" () { return this.#content; }
// "getBoardId" () { return this.#boardId; } "getBoardId" () { return this.#boardId; }
// "getPostId" () { return this.#postId; } "getPostId" () { return this.#postId; }
//
// "getParent" () { return this.#parent; } "getParent" () { return this.#parent; }
// "__setParent" (inst) { return this.#parent = inst; } "__setParent" (inst) { return this.#parent = inst; }
//
// } }
//
// globalThis.LCNPostWrapper = class LCNPostWrapper { globalThis.LCNPostWrapper = class LCNPostWrapper {
//
// static nodeAttrib = "$LCNPostWrapper"; static nodeAttrib = "$LCNPostWrapper";
// static selector = ".post-wrapper"; static selector = ".post-wrapper";
// #wrapper = null; #wrapper = null;
// #eitaLink = null; #eitaLink = null;
// #eitaId = null; #eitaId = null;
// #eitaHref = null #eitaHref = null
// #content = null; #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) {
// assert.ok(wrapper.classList.contains("post-wrapper"), "Arty must be expected Element.") assert.ok(wrapper.classList.contains("post-wrapper"), "Arty must be expected Element.")
// this.#wrapper = wrapper this.#wrapper = wrapper
// this.#eitaLink = wrapper.querySelector(".eita-link") this.#eitaLink = wrapper.querySelector(".eita-link")
// this.#eitaId = this.#eitaLink.id this.#eitaId = this.#eitaLink.id
// this.#eitaHref = this.#eitaLink.href this.#eitaHref = this.#eitaLink.href
// void Array.prototype.find.apply(wrapper.children, [ void Array.prototype.find.apply(wrapper.children, [
// el => { el => {
// if (el.classList.contains("thread")) { if (el.classList.contains("thread")) {
// return this.#content = LCNThread.assign(el) return this.#content = LCNThread.assign(el)
// } else if (el.classList.contains("postcontainer")) { } else if (el.classList.contains("postcontainer")) {
// return this.#content = LCNPostContainer.assign(el) return this.#content = LCNPostContainer.assign(el)
// } }
// } }
// ]) ])
//
// assert.ok(this.#content, "Wrapper should contain content.") assert.ok(this.#content, "Wrapper should contain content.")
// assert.equal(this.#content.getParent(), null, "Content should not have parent.") assert.equal(this.#content.getParent(), null, "Content should not have parent.")
// this.#content.__setParent(this) this.#content.__setParent(this)
// } }
//
// "getPost" () { "getPost" () {
// const post = this.getContent().getContent() const post = this.getContent().getContent()
// assert.ok(post instanceof LCNPost, "Post should be LCNPost.") assert.ok(post instanceof LCNPost, "Post should be LCNPost.")
// return post return post
// } }
//
// "getElement" () { return this.#wrapper; } "getElement" () { return this.#wrapper; }
// "getContent" () { return this.#content; } "getContent" () { return this.#content; }
// "getEitaId" () { return this.#eitaId; } "getEitaId" () { return this.#eitaId; }
// "getEitaHref" () { return this.#eitaHref; } "getEitaHref" () { return this.#eitaHref; }
// "getEitaLink" () { return this.#eitaLink; } "getEitaLink" () { return this.#eitaLink; }
//
// } }
//
// globalThis.LCNSetting = class LCNSetting { globalThis.LCNSetting = class LCNSetting {
// #id = null; #id = null;
// #eventId = null; #eventId = null;
// #label = null; #label = null;
// #value = null; #value = null;
// #valueDefault = null; #valueDefault = null;
//
// static "build" (id) { return new this(id); } static "build" (id) { return new this(id); }
//
// "constructor" (id) { "constructor" (id) {
// this.#id = id; this.#id = id;
// this.#eventId = `lcnsetting::${this.#id}` this.#eventId = `lcnsetting::${this.#id}`
// } }
//
// #getValue () { #getValue () {
// const v = localStorage.getItem(this.#id) const v = localStorage.getItem(this.#id)
// if (v != null) { if (v != null) {
// return this.__builtinValueImporter(v) return this.__builtinValueImporter(v)
// } else { } else {
// return this.#valueDefault return this.#valueDefault
// } }
// } }
//
// "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) {
// this.#value = v this.#value = v
// localStorage.setItem(this.#id, this.__builtinValueExporter(this.#value)) localStorage.setItem(this.#id, this.__builtinValueExporter(this.#value))
// setTimeout(() => $(document).trigger(`${this.#eventId}::change`, [ v, this ]), 1) setTimeout(() => $(document).trigger(`${this.#eventId}::change`, [ v, this ]), 1)
// } }
// } }
//
// "getLabel" () { return this.#label; } "getLabel" () { return this.#label; }
// "setLabel" (label) { this.#label = label; return this; } "setLabel" (label) { this.#label = label; return this; }
//
// "getDefaultValue" () { return this.#valueDefault; } "getDefaultValue" () { return this.#valueDefault; }
// "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) { this.#id = `${prefix}_${this.#id}`; } __setIdPrefix (prefix) { this.#id = `${prefix}_${this.#id}`; }
// } }
//
// globalThis.LCNToggleSetting = class LCNToggleSetting extends LCNSetting { globalThis.LCNToggleSetting = class LCNToggleSetting extends LCNSetting {
// __builtinValueImporter (v) { return v == "1"; } __builtinValueImporter (v) { return v == "1"; }
// __builtinValueExporter (v) { return v ? "1" : ""; } __builtinValueExporter (v) { return v ? "1" : ""; }
// __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 txt = document.createElement("label")
// txt.innerText = this.getLabel() txt.innerText = this.getLabel()
// chk.type = "checkbox" chk.type = "checkbox"
// chk.checked = this.getValue() chk.checked = this.getValue()
// chk.addEventListener("click", e => { chk.addEventListener("click", e => {
// e.preventDefault(); e.preventDefault();
// this.setValue(!this.getValue()) this.setValue(!this.getValue())
// }) })
// this.onChange(v => chk.checked = v) this.onChange(v => chk.checked = v)
//
// div.appendChild(chk) div.appendChild(chk)
// div.appendChild(txt) div.appendChild(txt)
// return div return div
// } }
// } }
//
// globalThis.LCNSettingsSubcategory = class LCNSettingsSubcategory { globalThis.LCNSettingsSubcategory = class LCNSettingsSubcategory {
//
// #tab_id = null; #tab_id = null;
// #id = null; #id = null;
//
// #fieldset = null; #fieldset = null;
// #legend = null; #legend = null;
// #label = null; #label = null;
//
// static "for" (tab_id, id) { static "for" (tab_id, id) {
// const domid = `lcnssc_${tab_id}_${id}` const domid = `lcnssc_${tab_id}_${id}`
// const inst = document.getElementById(domid)?.$LCNSettingsSubcategory const inst = document.getElementById(domid)?.$LCNSettingsSubcategory
// if (inst == null) { if (inst == null) {
// const fieldset = document.createElement("fieldset") const fieldset = document.createElement("fieldset")
// const legend = document.createElement("legend") const legend = document.createElement("legend")
// fieldset.id = domid fieldset.id = domid
// fieldset.appendChild(legend) fieldset.appendChild(legend)
//
// // XXX: extend_tab only takes a string so this hacky workaround is used to let us use the regular dom api // 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>`) Options.extend_tab(tab_id, `<div id="__${domid}" hidden></div>`)
// const div = document.getElementById(`__${domid}`)?.parentElement const div = document.getElementById(`__${domid}`)?.parentElement
// assert.ok(div) assert.ok(div)
//
// div.replaceChildren(fieldset) div.replaceChildren(fieldset)
// return new this(tab_id, id, fieldset) return new this(tab_id, id, fieldset)
// } else { } else {
// return inst return inst
// } }
// } }
//
// "constructor" (tab_id, id, fieldset) { "constructor" (tab_id, id, fieldset) {
// this.#tab_id = tab_id this.#tab_id = tab_id
// this.#id = id this.#id = id
// this.#fieldset = fieldset this.#fieldset = fieldset
// this.#legend = this.#fieldset.querySelector("legend") this.#legend = this.#fieldset.querySelector("legend")
// this.#fieldset.$LCNSettingsSubcategory = this this.#fieldset.$LCNSettingsSubcategory = this
// } }
//
// "getLabel" () { return this.#label; } "getLabel" () { return this.#label; }
// "setLabel" (label) { this.#legend.innerText = this.#label = label; return this; } "setLabel" (label) { this.#legend.innerText = this.#label = label; return this; }
// "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.__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)
// } }
//
// return this return this
// } }
//
// } }
//
// $().ready(() => { $().ready(() => {
// LCNSite.INSTANCE = new LCNSite(); LCNSite.INSTANCE = new LCNSite();
//
// for (const clazz of [ LCNPost, LCNPostInfo, LCNThread, LCNPostContainer, LCNPostWrapper ]) { for (const clazz of [ LCNPost, LCNPostInfo, LCNThread, LCNPostContainer, LCNPostWrapper ]) {
// clazz.allNodes = (node=document) => node.querySelectorAll(clazz.selector) clazz.allNodes = (node=document) => node.querySelectorAll(clazz.selector)
// clazz.all = (node=document) => Array.prototype.map.apply(clazz.allNodes(node), [ elem => clazz.assign(elem) ]); 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.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))) clazz.forEach = (fn, node=document) => clazz.allNodes(node).forEach(elem => fn(clazz.assign(elem)))
// clazz.filter = (fn, node=document) => clazz.all(node).filter(fn) clazz.filter = (fn, node=document) => clazz.all(node).filter(fn)
// clazz.find = fn => clazz.all().find(fn) clazz.find = fn => clazz.all().find(fn)
// clazz.first = (node=document) => clazz.assign(node.querySelector(clazz.selector)) clazz.first = (node=document) => clazz.assign(node.querySelector(clazz.selector))
// clazz.last = (node=document) => clazz.assign(Array.prototype.at.apply(clazz.allNodes(node), [ -1 ])) clazz.last = (node=document) => clazz.assign(Array.prototype.at.apply(clazz.allNodes(node), [ -1 ]))
// } }
//
// // XXX: May be a cleaner way to do this but this should be fine for now. // 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(); } for (const clazz of [ LCNPostContainer, LCNPostWrapper, LCNThread, LCNPost ]) { void clazz.all(); }
// $(document).on("new_post", (e, post) => { $(document).on("new_post", (e, post) => {
// if (LCNSite.INSTANCE.isModRecentsPage()) { if (LCNSite.INSTANCE.isModRecentsPage()) {
// void LCNPostWrapper.all() void LCNPostWrapper.all()
// } else { } else {
// void LCNPostContainer.all() void LCNPostContainer.all()
// } }
// }) })
//
// $(window).on("focus", () => LCNSite.INSTANCE.clearUnseen()) $(window).on("focus", () => LCNSite.INSTANCE.clearUnseen())
// $(document.body).on("mousemove", () => LCNSite.INSTANCE.clearUnseen()) $(document.body).on("mousemove", () => LCNSite.INSTANCE.clearUnseen())
// }) })

View File

@ -35,7 +35,7 @@ $().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()) / 30000))
secondsCounter = secondsCounter > 1000 ? 1000 : secondsCounter secondsCounter = secondsCounter > 1000 ? 1000 : secondsCounter
secondsCounter = secondsCounter < 11 ? 11 : secondsCounter secondsCounter = secondsCounter < 11 ? 11 : secondsCounter
} }
@ -58,24 +58,43 @@ $().ready(() => {
} }
} }
const findMissingReplies = (thread_op, thread_dom, thread_latest) => { const handleThreadUpdate = async (thread) => {
const lastPostTs = (thread_dom.at(-1)?.getInfo() ?? thread_op).getCreatedAt().getTime() const threadPost = thread.getContent()
const missing = []
for (const pc of thread_latest.reverse()) { const res = await fetch(location.href, {
"signal": abortable.signal
})
if (res.ok) {
const dom = parser.parseFromString(await res.text(), "text/html")
const livePCList = Array.prototype.map.apply(dom.querySelectorAll(`#thread_${threadPost.getInfo().getThreadId()} > .postcontainer`), [ pc => LCNPostContainer.assign(pc) ])
updateThreadFn(thread, livePCList);
} else if (res.status == 404) {
threadState = String(res.status)
} else {
throw new Error(`Server responded with non-OK status '${res.status}'`)
}
}
function updateThreadFn(thread, lcn_pc_list) {
const threadPost = thread.getContent()
const threadReplies = thread.getReplies()
const lastPostC = threadReplies.at(-1).getParent()
const lastPostTs = lastPostC.getContent().getInfo().getCreatedAt().getTime()
const livePCList = lcn_pc_list;
const documentPCList = [ threadPost, ...threadReplies.map(p => p.getParent()) ]
const missingPCList = []
for (const pc of livePCList.reverse()) {
if (pc.getContent().getInfo().getCreatedAt().getTime() > lastPostTs) { if (pc.getContent().getInfo().getCreatedAt().getTime() > lastPostTs) {
missing.unshift(pc) missingPCList.unshift(pc)
} else { } else {
break break
} }
} }
return missing
}
const updateRepliesFn = (thread, missingPCList) => {
if (missingPCList.length) { if (missingPCList.length) {
const documentPCList = [ thread.getContent(), ...(thread.getReplies()).map(p => p.getParent()) ]
for (const pc of missingPCList) { for (const pc of missingPCList) {
documentPCList.at(-1).getElement().after(pc.getElement()) documentPCList.at(-1).getElement().after(pc.getElement())
documentPCList.push(pc) documentPCList.push(pc)
@ -87,29 +106,7 @@ $().ready(() => {
LCNSite.INSTANCE.setUnseen(LCNSite.INSTANCE.getUnseen() + missingPCList.length) LCNSite.INSTANCE.setUnseen(LCNSite.INSTANCE.getUnseen() + missingPCList.length)
} }
}
const updateThreadFn = async (thread, dom) => {
const threadPost = thread.getContent()
const threadReplies = thread.getReplies()
const missingPCList = findMissingReplies(
threadPost,
threadReplies,
LCNPostContainer.all(dom.querySelector(`#thread_${threadPost.getInfo().getThreadId()}`)))
updateRepliesFn(thread, missingPCList)
}
const fetchThreadFn = async () => {
const res = await fetch(location.href, { "signal": abortable.signal })
if (res.ok) {
return parser.parseFromString(await res.text(), "text/html")
} else {
if (res.status == 404) {
threadState = String(res.status)
}
throw new Error(`Server responded with non-OK status '${res.status}'`)
}
} }
const onTickClean = () => { const onTickClean = () => {
@ -132,7 +129,7 @@ $().ready(() => {
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()) await handleThreadUpdate(thread)
} }
const threadEl = thread.getElement() const threadEl = thread.getElement()
@ -151,26 +148,6 @@ $().ready(() => {
} }
} }
$(document).on("ajax_after_post", (_, xhr_body) => {
if (kIsEnabled.getValue() && xhr_body != null) {
if (!xhr_body.mod) {
const thread = LCNThread.first()
const dom = parser.parseFromString(xhr_body.thread, "text/html")
updateThreadFn(thread, dom)
updateSecondsByTSLP(thread.getReplies().at(-1).getInfo())
} else {
$(document).trigger("thread_manual_refresh")
}
}
})
$(document).on("thread_manual_refresh", () => {
if (kIsEnabled.getValue() && secondsCounter >= 0) {
secondsCounter = 0
onTickFn()
}
})
let floaterLinkBox = null let floaterLinkBox = null
const onStateChangeFn = v => { const onStateChangeFn = v => {
onTickClean() onTickClean()
@ -187,7 +164,10 @@ $().ready(() => {
threadUpdateStatus.innerText = "…" threadUpdateStatus.innerText = "…"
threadUpdateLink.addEventListener("click", e => { threadUpdateLink.addEventListener("click", e => {
e.preventDefault() e.preventDefault()
$(document).trigger("thread_manual_refresh") if (secondsCounter >= 0) {
secondsCounter = 0
onTickFn()
}
}) })
threadUpdateLink.href = "#" threadUpdateLink.href = "#"
threadUpdateLink.appendChild(new Text("Refresh: ")) threadUpdateLink.appendChild(new Text("Refresh: "))
@ -231,7 +211,8 @@ $().ready(() => {
} }
} }
$(document).trigger("thread_manual_refresh") secondsCounter = 0
setTimeout(onTickFn, 1)
} else { } else {
floaterLinkBox?.remove() floaterLinkBox?.remove()
floaterLinkBox = null floaterLinkBox = null
@ -247,5 +228,26 @@ $().ready(() => {
kIsEnabled.onChange(onStateChangeFn) kIsEnabled.onChange(onStateChangeFn)
onStateChangeFn(kIsEnabled.getValue()) onStateChangeFn(kIsEnabled.getValue())
$(document).on("ajax_after_post", onNewPost);
function onNewPost(_, post_response) {
if (post_response == null) {
console.log("onNewPost data is null, can't do anything.");
return;
}
const thread_dom = parser.parseFromString(
post_response['thread'],
"text/html");
const thread_id_sel = "#thread_" + post_response['thread_id'];
const post_containers = [...thread_dom.querySelectorAll(`${thread_id_sel} > .postcontainer`)]
.map(elem => LCNPostContainer.assign(elem));
const thread_elem = document.querySelector(thread_id_sel);
const lcn_thread = new LCNThread(thread_elem);
updateThreadFn(lcn_thread, post_containers);
}
} }
}) })

View File

@ -6,38 +6,37 @@
const assert = { const assert = {
"equal": (actual, expected, message="No message set") => { "equal": (actual, expected, message="No message set") => {
if (actual !== expected) { if (actual !== expected) {
const err = new Error(`Assertion Failed. ${message}`); const err = new Error(`Assertion Failed. ${message}`)
err.data = { actual, expected} err.data = { actual, expected}
//Error.captureStackTrace?.(err, assert.equal); // Seems like there's no such thing as captureStackTrace in firefox?
debugger; //Error.captureStackTrace(err, assert.equal)
throw err; debugger
throw err
} }
}, },
"ok": (actual, message="No message set") => { "ok": (actual, message="No message set") => {
if (!actual) { if (!actual) {
const err = new Error(`Assertion Failed. ${message}`); const err = new Error(`Assertion Failed. ${message}`)
err.data = { actual } err.data = { actual }
//Error.captureStackTrace?.(err, assert.ok); // Error.captureStackTrace(err, assert.ok)
debugger; debugger
throw err; throw err
}
} }
} }
};
if (AbortSignal.any == null) { AbortSignal.any ??= function (signals) {
AbortSignal.any = (signals) => { const controller = new AbortController()
const controller = new AbortController();
const abortFn = () => { const abortFn = () => {
for (const signal of signals) { for (const signal of signals) {
signal.removeEventListener("abort", abortFn); signal.removeEventListener("abort", abortFn)
} }
controller.abort(); controller.abort()
} }
for (const signal of signals) { for (const signal of signals) {
signal.addEventListener("abort", abortFn); signal.addEventListener("abort", abortFn)
} }
return controller.signal; return controller.signal
}
} }

View File

@ -1495,8 +1495,7 @@ function handle_post(){
'noko' => $noko, 'noko' => $noko,
'id' => $id, 'id' => $id,
'thread_id' => $thread_id, 'thread_id' => $thread_id,
'thread' => $rendered_thread, 'thread' => $rendered_thread
'mod' => !!$post['mod']
)); ));
} }