From 11011a0ff263e94d1c3e434f3a5c1a3f54a7eb94 Mon Sep 17 00:00:00 2001 From: Jon <134811123+jonsmy@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:18:56 +0000 Subject: [PATCH] js/lcn/classes.js: small edits, add unseen tracker --- js/lcn/classes.js | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/js/lcn/classes.js b/js/lcn/classes.js index 65157324..035173e9 100644 --- a/js/lcn/classes.js +++ b/js/lcn/classes.js @@ -25,6 +25,34 @@ globalThis.LCNSite = class LCNSite { "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) { + const bool = !!int + if (bool != !!this.#unseen) { + this.setFaviconType(bool ? "reply" : null) + } + this.#unseen = int + this.#doTitleUpdate() + } + + #pageTitle = document.title; + "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) { + if (this.#favicon == null) { + this.#favicon = document.createElement("link") + this.#favicon.rel = "shortcut icon" + document.head.appendChild(this.#favicon) + } + + this.#favicon.href = `/favicon${type ? "-" + type : ""}.ico` + } } globalThis.LCNPostInfo = class LCNPostInfo { @@ -86,12 +114,18 @@ globalThis.LCNPostInfo = class LCNPostInfo { "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() + } + } globalThis.LCNPost = class LCNPost { @@ -175,8 +209,8 @@ globalThis.LCNThread = class LCNThread { this.#op.__setParent(this) } - "getThread" () { return this.#thread; } - "getOP" () { return this.#op; } + "getElement" () { return this.#thread; } + "getContent" () { return this.#op; } "getPosts" () { return Array.prototype.map.apply(this.#thread.querySelectorAll(".post"), [ el => LCNPost.assign(el) ]); } "getReplies" () { return Array.prototype.map.apply(this.#thread.querySelectorAll(".post:not(.op)"), [ el => LCNPost.assign(el) ]); } @@ -250,7 +284,13 @@ globalThis.LCNPostWrapper = class LCNPostWrapper { this.#content.__setParent(this) } - "getWrapper" () { return this.#wrapper; } + "getPost" () { + const post = this.getContent().getContent() + assert.ok(post instanceof LCNPost, "Post should be LCNPost.") + return post + } + + "getElement" () { return this.#wrapper; } "getContent" () { return this.#content; } "getEitaId" () { return this.#eitaId; } "getEitaHref" () { return this.#eitaHref; }