var to const

This commit is contained in:
Lalle 2023-04-28 14:53:25 +02:00
parent 69051d6095
commit 5183de55b6
No known key found for this signature in database
GPG Key ID: A6583D207A8F6B0D
3 changed files with 137 additions and 137 deletions

View File

@ -30,7 +30,7 @@ import UnreadIndex from './UnreadIndex'
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/ */
var ThreadWatcher = { const ThreadWatcher = {
init() { init() {
let sc let sc
if (!(this.enabled = Conf['Thread Watcher'])) { return } if (!(this.enabled = Conf['Thread Watcher'])) { return }
@ -91,16 +91,16 @@ var ThreadWatcher = {
href: 'javascript:;', href: 'javascript:;',
className: 'has-shortcut-text' className: 'has-shortcut-text'
} }
, {innerHTML: '<span></span><span class="shortcut-text">Alt+click</span>'}), , { innerHTML: '<span></span><span class="shortcut-text">Alt+click</span>' }),
order: 6, order: 6,
open({thread}) { open({ thread }) {
if (Conf['Index Mode'] !== 'catalog') { return false } if (Conf['Index Mode'] !== 'catalog') { return false }
this.el.firstElementChild.textContent = ThreadWatcher.isWatched(thread) ? this.el.firstElementChild.textContent = ThreadWatcher.isWatched(thread) ?
'Unwatch' 'Unwatch'
: :
'Watch' 'Watch'
if (this.cb) { $.off(this.el, 'click', this.cb) } if (this.cb) { $.off(this.el, 'click', this.cb) }
this.cb = function() { this.cb = function () {
$.event('CloseMenu') $.event('CloseMenu')
return ThreadWatcher.toggle(thread) return ThreadWatcher.toggle(thread)
} }
@ -123,11 +123,11 @@ var ThreadWatcher = {
}, },
isWatched(thread) { isWatched(thread) {
return !!ThreadWatcher.db?.get({boardID: thread.board.ID, threadID: thread.ID}) return !!ThreadWatcher.db?.get({ boardID: thread.board.ID, threadID: thread.ID })
}, },
isWatchedRaw(boardID, threadID) { isWatchedRaw(boardID, threadID) {
return !!ThreadWatcher.db?.get({boardID, threadID}) return !!ThreadWatcher.db?.get({ boardID, threadID })
}, },
setToggler(toggler, isWatched) { setToggler(toggler, isWatched) {
@ -151,13 +151,13 @@ var ThreadWatcher = {
const siteID = g.SITE.ID const siteID = g.SITE.ID
const boardID = this.board.ID const boardID = this.board.ID
const threadID = this.thread.ID const threadID = this.thread.ID
const data = ThreadWatcher.db.get({siteID, boardID, threadID}) const data = ThreadWatcher.db.get({ siteID, boardID, threadID })
ThreadWatcher.setToggler(toggler, !!data) ThreadWatcher.setToggler(toggler, !!data)
$.on(toggler, 'click', ThreadWatcher.cb.toggle) $.on(toggler, 'click', ThreadWatcher.cb.toggle)
// Add missing excerpt for threads added by Auto Watch // Add missing excerpt for threads added by Auto Watch
if (data && (data.excerpt == null)) { if (data && (data.excerpt == null)) {
return $.queueTask(() => { return $.queueTask(() => {
return ThreadWatcher.update(siteID, boardID, threadID, {excerpt: Get.threadExcerpt(this.thread)}) return ThreadWatcher.update(siteID, boardID, threadID, { excerpt: Get.threadExcerpt(this.thread) })
}) })
} }
}, },
@ -206,33 +206,33 @@ var ThreadWatcher = {
}, },
pruneDeads() { pruneDeads() {
if ($.hasClass(this, 'disabled')) { return } if ($.hasClass(this, 'disabled')) { return }
for (const {siteID, boardID, threadID, data} of ThreadWatcher.getAll()) { for (const { siteID, boardID, threadID, data } of ThreadWatcher.getAll()) {
if (data.isDead) { if (data.isDead) {
ThreadWatcher.db.delete({siteID, boardID, threadID}) ThreadWatcher.db.delete({ siteID, boardID, threadID })
} }
} }
ThreadWatcher.refresh() ThreadWatcher.refresh()
return $.event('CloseMenu') return $.event('CloseMenu')
}, },
dismiss() { dismiss() {
for (const {siteID, boardID, threadID, data} of ThreadWatcher.getAll()) { for (const { siteID, boardID, threadID, data } of ThreadWatcher.getAll()) {
if (data.quotingYou) { if (data.quotingYou) {
ThreadWatcher.update(siteID, boardID, threadID, {dismiss: data.quotingYou || 0}) ThreadWatcher.update(siteID, boardID, threadID, { dismiss: data.quotingYou || 0 })
} }
} }
return $.event('CloseMenu') return $.event('CloseMenu')
}, },
toggle() { toggle() {
const {thread} = Get.postFromNode(this) const { thread } = Get.postFromNode(this)
return ThreadWatcher.toggle(thread) return ThreadWatcher.toggle(thread)
}, },
rm() { rm() {
const {siteID} = this.parentNode.dataset const { siteID } = this.parentNode.dataset
const [boardID, threadID] = Array.from(this.parentNode.dataset.fullID.split('.')) const [boardID, threadID] = Array.from(this.parentNode.dataset.fullID.split('.'))
return ThreadWatcher.rm(siteID, boardID, +threadID) return ThreadWatcher.rm(siteID, boardID, +threadID)
}, },
post(e) { post(e) {
const {boardID, threadID, postID} = e.detail const { boardID, threadID, postID } = e.detail
const cb = PostRedirect.delay() const cb = PostRedirect.delay()
if (postID === threadID) { if (postID === threadID) {
if (Conf['Auto Watch']) { if (Conf['Auto Watch']) {
@ -243,7 +243,7 @@ var ThreadWatcher = {
} }
}, },
onIndexUpdate(e) { onIndexUpdate(e) {
const {db} = ThreadWatcher const { db } = ThreadWatcher
const siteID = g.SITE.ID const siteID = g.SITE.ID
const boardID = g.BOARD.ID const boardID = g.BOARD.ID
let nKilled = 0 let nKilled = 0
@ -253,10 +253,10 @@ var ThreadWatcher = {
if (!data?.isDead && !e.detail.threads.includes(`${boardID}.${threadID}`)) { if (!data?.isDead && !e.detail.threads.includes(`${boardID}.${threadID}`)) {
if (!e.detail.threads.some(fullID => +fullID.split('.')[1] > threadID)) { continue } if (!e.detail.threads.some(fullID => +fullID.split('.')[1] > threadID)) { continue }
if (Conf['Auto Prune'] || !(data && (typeof data === 'object'))) { // corrupt data if (Conf['Auto Prune'] || !(data && (typeof data === 'object'))) { // corrupt data
db.delete({boardID, threadID}) db.delete({ boardID, threadID })
nKilled++ nKilled++
} else { } else {
ThreadWatcher.fetchStatus({siteID, boardID, threadID, data}) ThreadWatcher.fetchStatus({ siteID, boardID, threadID, data })
} }
} }
} }
@ -273,12 +273,12 @@ var ThreadWatcher = {
requests: [], requests: [],
fetched: 0, fetched: 0,
fetch(url, {siteID, force}, args, cb) { fetch(url, { siteID, force }, args, cb) {
if (ThreadWatcher.requests.length === 0) { if (ThreadWatcher.requests.length === 0) {
ThreadWatcher.status.textContent = '...' ThreadWatcher.status.textContent = '...'
$.addClass(ThreadWatcher.refreshButton, 'fa-spin') $.addClass(ThreadWatcher.refreshButton, 'fa-spin')
} }
const onloadend = function() { const onloadend = function () {
if (this.finished) { return } if (this.finished) { return }
this.finished = true this.finished = true
ThreadWatcher.fetched++ ThreadWatcher.fetched++
@ -326,13 +326,13 @@ var ThreadWatcher = {
const boards = ThreadWatcher.dbLM.data[siteID] const boards = ThreadWatcher.dbLM.data[siteID]
for (const boardID in boards.boards) { for (const boardID in boards.boards) {
const data = boards.boards[boardID] const data = boards.boards[boardID]
if (ThreadWatcher.db.get({siteID, boardID})) { if (ThreadWatcher.db.get({ siteID, boardID })) {
for (const url in data) { for (const url in data) {
const date = data[url] const date = data[url]
lm[url] = date lm[url] = date
} }
} else { } else {
ThreadWatcher.dbLM.delete({siteID, boardID}) ThreadWatcher.dbLM.delete({ siteID, boardID })
} }
} }
} }
@ -342,7 +342,7 @@ var ThreadWatcher = {
let middle let middle
clearTimeout(ThreadWatcher.timeout) clearTimeout(ThreadWatcher.timeout)
if (!Conf['Auto Update Thread Watcher']) { return } if (!Conf['Auto Update Thread Watcher']) { return }
const {db} = ThreadWatcher const { db } = ThreadWatcher
const interval = Conf['Show Page'] || (ThreadWatcher.unreadEnabled && Conf['Show Unread Count']) ? 5 * MINUTE : 2 * HOUR const interval = Conf['Show Page'] || (ThreadWatcher.unreadEnabled && Conf['Show Unread Count']) ? 5 * MINUTE : 2 * HOUR
const now = Date.now() const now = Date.now()
if ((now - interval >= ((middle = db.data.lastChecked || 0)) || middle > now) && !d.hidden && !!d.hasFocus()) { if ((now - interval >= ((middle = db.data.lastChecked || 0)) || middle > now) && !d.hidden && !!d.hasFocus()) {
@ -359,14 +359,14 @@ var ThreadWatcher = {
} }
}, },
fetchAllStatus(interval=0) { fetchAllStatus(interval = 0) {
ThreadWatcher.status.textContent = '...' ThreadWatcher.status.textContent = '...'
$.addClass(ThreadWatcher.refreshButton, 'fa-spin') $.addClass(ThreadWatcher.refreshButton, 'fa-spin')
ThreadWatcher.syncing = true ThreadWatcher.syncing = true
const dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter(x => x) const dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter(x => x)
let n = 0 let n = 0
return dbs.map((dbi) => return dbs.map((dbi) =>
dbi.forceSync(function() { dbi.forceSync(function () {
if ((++n) === dbs.length) { if ((++n) === dbs.length) {
let middle let middle
if (!ThreadWatcher.syncing) { return } // aborted if (!ThreadWatcher.syncing) { return } // aborted
@ -375,7 +375,7 @@ var ThreadWatcher = {
// XXX On vichan boards, last_modified field of threads.json does not account for sage posts. // XXX On vichan boards, last_modified field of threads.json does not account for sage posts.
// Occasionally check replies field of catalog.json to find these posts. // Occasionally check replies field of catalog.json to find these posts.
let middle1 let middle1
const {db} = ThreadWatcher const { db } = ThreadWatcher
const now = Date.now() const now = Date.now()
const deep = !(now - (2 * HOUR) < ((middle1 = db.data.lastChecked2 || 0)) && middle1 <= now) const deep = !(now - (2 * HOUR) < ((middle1 = db.data.lastChecked2 || 0)) && middle1 <= now)
const boards = ThreadWatcher.getAll(true) const boards = ThreadWatcher.getAll(true)
@ -396,27 +396,27 @@ var ThreadWatcher = {
if (!board.some(thread => !thread.data.isDead)) { return } if (!board.some(thread => !thread.data.isDead)) { return }
let force = false let force = false
for (const thread of board) { for (const thread of board) {
const {data} = thread const { data } = thread
if (!data.isDead && (data.last !== -1)) { if (!data.isDead && (data.last !== -1)) {
if (Conf['Show Page'] && (data.page == null)) { force = true } if (Conf['Show Page'] && (data.page == null)) { force = true }
if ((data.modified == null)) { force = (thread.force = true) } if ((data.modified == null)) { force = (thread.force = true) }
} }
} }
const {siteID, boardID} = board[0] const { siteID, boardID } = board[0]
const site = g.sites[siteID] const site = g.sites[siteID]
if (!site) { return } if (!site) { return }
const urlF = deep && site.threadModTimeIgnoresSage ? 'catalogJSON' : 'threadsListJSON' const urlF = deep && site.threadModTimeIgnoresSage ? 'catalogJSON' : 'threadsListJSON'
const url = site.urls[urlF]?.({siteID, boardID}) const url = site.urls[urlF]?.({ siteID, boardID })
if (!url) { return } if (!url) { return }
return ThreadWatcher.fetch(url, {siteID, force}, [board, url], ThreadWatcher.parseBoard) return ThreadWatcher.fetch(url, { siteID, force }, [board, url], ThreadWatcher.parseBoard)
}, },
parseBoard(board, url) { parseBoard(board, url) {
let page, thread let page, thread
if (this.status !== 200) { return } if (this.status !== 200) { return }
const {siteID, boardID} = board[0] const { siteID, boardID } = board[0]
const lmDate = this.getResponseHeader('Last-Modified') const lmDate = this.getResponseHeader('Last-Modified')
ThreadWatcher.dbLM.extend({siteID, boardID, val: $.item(url, lmDate)}) ThreadWatcher.dbLM.extend({ siteID, boardID, val: $.item(url, lmDate) })
const threads = dict() const threads = dict()
let pageLength = 0 let pageLength = 0
let nThreads = 0 let nThreads = 0
@ -444,16 +444,16 @@ var ThreadWatcher = {
} }
} }
for (thread of board) { for (thread of board) {
const {threadID, data} = thread const { threadID, data } = thread
if (threads[threadID]) { if (threads[threadID]) {
var index, modified, replies; var index, modified, replies;
({page, index, modified, replies} = threads[threadID]) ({ page, index, modified, replies } = threads[threadID])
if (Conf['Show Page']) { if (Conf['Show Page']) {
const lastPage = g.sites[siteID].isPrunedByAge?.({siteID, boardID}) ? const lastPage = g.sites[siteID].isPrunedByAge?.({ siteID, boardID }) ?
threadID === oldest threadID === oldest
: :
index >= (nThreads - pageLength) index >= (nThreads - pageLength)
ThreadWatcher.update(siteID, boardID, threadID, {page, lastPage}) ThreadWatcher.update(siteID, boardID, threadID, { page, lastPage })
} }
if (ThreadWatcher.unreadEnabled && Conf['Show Unread Count']) { if (ThreadWatcher.unreadEnabled && Conf['Show Unread Count']) {
if ((modified !== data.modified) || ((replies != null) && (replies !== data.replies))) { if ((modified !== data.modified) || ((replies != null) && (replies !== data.replies))) {
@ -468,22 +468,22 @@ var ThreadWatcher = {
}, },
fetchStatus(thread) { fetchStatus(thread) {
const {siteID, boardID, threadID, data, force} = thread const { siteID, boardID, threadID, data, force } = thread
const url = g.sites[siteID]?.urls.threadJSON?.({siteID, boardID, threadID}) const url = g.sites[siteID]?.urls.threadJSON?.({ siteID, boardID, threadID })
if (!url) { return } if (!url) { return }
if (data.isDead && !force) { return } if (data.isDead && !force) { return }
if (data.last === -1) { return } // 404 or no JSON API if (data.last === -1) { return } // 404 or no JSON API
return ThreadWatcher.fetch(url, {siteID, force}, [thread], ThreadWatcher.parseStatus) return ThreadWatcher.fetch(url, { siteID, force }, [thread], ThreadWatcher.parseStatus)
}, },
parseStatus(thread, isArchiveURL) { parseStatus(thread, isArchiveURL) {
let isDead, last let isDead, last
let {siteID, boardID, threadID, data, newData, force} = thread let { siteID, boardID, threadID, data, newData, force } = thread
const site = g.sites[siteID] const site = g.sites[siteID]
if ((this.status === 200) && this.response) { if ((this.status === 200) && this.response) {
let isArchived let isArchived
last = this.response.posts[this.response.posts.length-1].no last = this.response.posts[this.response.posts.length - 1].no
const replies = this.response.posts.length-1 const replies = this.response.posts.length - 1
isDead = (isArchived = !!(this.response.posts[0].archived || isArchiveURL)) isDead = (isArchived = !!(this.response.posts[0].archived || isArchiveURL))
if (isDead && Conf['Auto Prune']) { if (isDead && Conf['Auto Prune']) {
ThreadWatcher.rm(siteID, boardID, threadID) ThreadWatcher.rm(siteID, boardID, threadID)
@ -492,14 +492,14 @@ var ThreadWatcher = {
if ((last === data.last) && (isDead === data.isDead) && (isArchived === data.isArchived)) { return } if ((last === data.last) && (isDead === data.isDead) && (isArchived === data.isArchived)) { return }
const lastReadPost = ThreadWatcher.unreaddb.get({siteID, boardID, threadID, defaultValue: 0}) const lastReadPost = ThreadWatcher.unreaddb.get({ siteID, boardID, threadID, defaultValue: 0 })
let unread = data.unread || 0 let unread = data.unread || 0
let quotingYou = data.quotingYou || 0 let quotingYou = data.quotingYou || 0
const youOP = !!QuoteYou.db?.get({siteID, boardID, threadID, postID: threadID}) const youOP = !!QuoteYou.db?.get({ siteID, boardID, threadID, postID: threadID })
for (const postObj of this.response.posts) { for (const postObj of this.response.posts) {
if ((postObj.no <= (data.last || 0)) || (postObj.no <= lastReadPost)) { continue } if ((postObj.no <= (data.last || 0)) || (postObj.no <= lastReadPost)) { continue }
if (QuoteYou.db?.get({siteID, boardID, threadID, postID: postObj.no})) { continue } if (QuoteYou.db?.get({ siteID, boardID, threadID, postID: postObj.no })) { continue }
let quotesYou = false let quotesYou = false
if (!Conf['Require OP Quote Link'] && youOP) { if (!Conf['Require OP Quote Link'] && youOP) {
@ -522,7 +522,7 @@ var ThreadWatcher = {
} }
if (!unread || (!quotingYou && quotesYou)) { if (!unread || (!quotingYou && quotesYou)) {
if (Filter.isHidden(site.Build.parseJSON(postObj, {siteID, boardID}))) { continue } if (Filter.isHidden(site.Build.parseJSON(postObj, { siteID, boardID }))) { continue }
} }
unread++ unread++
@ -530,17 +530,17 @@ var ThreadWatcher = {
} }
if (!newData) { newData = {} } if (!newData) { newData = {} }
$.extend(newData, {last, replies, isDead, isArchived, unread, quotingYou}) $.extend(newData, { last, replies, isDead, isArchived, unread, quotingYou })
return ThreadWatcher.update(siteID, boardID, threadID, newData) return ThreadWatcher.update(siteID, boardID, threadID, newData)
} else if (this.status === 404) { } else if (this.status === 404) {
const archiveURL = g.sites[siteID]?.urls.archivedThreadJSON?.({siteID, boardID, threadID}) const archiveURL = g.sites[siteID]?.urls.archivedThreadJSON?.({ siteID, boardID, threadID })
if (!isArchiveURL && archiveURL) { if (!isArchiveURL && archiveURL) {
return ThreadWatcher.fetch(archiveURL, {siteID, force}, [thread, true], ThreadWatcher.parseStatus) return ThreadWatcher.fetch(archiveURL, { siteID, force }, [thread, true], ThreadWatcher.parseStatus)
} else if (site.mayLackJSON && (data.last == null)) { } else if (site.mayLackJSON && (data.last == null)) {
return ThreadWatcher.update(siteID, boardID, threadID, {last: -1}) return ThreadWatcher.update(siteID, boardID, threadID, { last: -1 })
} else { } else {
return ThreadWatcher.update(siteID, boardID, threadID, {isDead: true}) return ThreadWatcher.update(siteID, boardID, threadID, { isDead: true })
} }
} }
}, },
@ -561,7 +561,7 @@ var ThreadWatcher = {
for (const threadID in threads) { for (const threadID in threads) {
const data = threads[threadID] const data = threads[threadID]
if (data && (typeof data === 'object')) { if (data && (typeof data === 'object')) {
(groupByBoard ? cont : all).push({siteID, boardID, threadID, data}) (groupByBoard ? cont : all).push({ siteID, boardID, threadID, data })
} }
} }
} }
@ -578,12 +578,12 @@ var ThreadWatcher = {
) )
$.on(x, 'click', ThreadWatcher.cb.rm) $.on(x, 'click', ThreadWatcher.cb.rm)
let {excerpt, isArchived} = data let { excerpt, isArchived } = data
if (!excerpt) { excerpt = `/${boardID}/ - No.${threadID}` } if (!excerpt) { excerpt = `/${boardID}/ - No.${threadID}` }
if (Conf['Show Site Prefix']) { excerpt = ThreadWatcher.prefixes[siteID] + excerpt } if (Conf['Show Site Prefix']) { excerpt = ThreadWatcher.prefixes[siteID] + excerpt }
const link = $.el('a', { const link = $.el('a', {
href: g.sites[siteID]?.urls.thread({siteID, boardID, threadID}, isArchived) || '', href: g.sites[siteID]?.urls.thread({ siteID, boardID, threadID }, isArchived) || '',
title: excerpt, title: excerpt,
className: 'watcher-link' className: 'watcher-link'
} }
@ -635,7 +635,7 @@ var ThreadWatcher = {
setPrefixes(threads) { setPrefixes(threads) {
const prefixes = dict() const prefixes = dict()
for (const {siteID} of threads) { for (const { siteID } of threads) {
if (siteID in prefixes) { continue } if (siteID in prefixes) { continue }
let len = 0 let len = 0
let prefix = '' let prefix = ''
@ -662,15 +662,15 @@ var ThreadWatcher = {
const nodes = [] const nodes = []
const threads = ThreadWatcher.getAll() const threads = ThreadWatcher.getAll()
ThreadWatcher.setPrefixes(threads) ThreadWatcher.setPrefixes(threads)
for (const {siteID, boardID, threadID, data} of threads) { for (const { siteID, boardID, threadID, data } of threads) {
// Add missing excerpt for threads added by Auto Watch // Add missing excerpt for threads added by Auto Watch
var thread var thread
if ((data.excerpt == null) && (siteID === g.SITE.ID) && (thread = g.threads.get(`${boardID}.${threadID}`)) && thread.OP) { if ((data.excerpt == null) && (siteID === g.SITE.ID) && (thread = g.threads.get(`${boardID}.${threadID}`)) && thread.OP) {
ThreadWatcher.db.extend({boardID, threadID, val: {excerpt: Get.threadExcerpt(thread)}}) ThreadWatcher.db.extend({ boardID, threadID, val: { excerpt: Get.threadExcerpt(thread) } })
} }
nodes.push(ThreadWatcher.makeLine(siteID, boardID, threadID, data)) nodes.push(ThreadWatcher.makeLine(siteID, boardID, threadID, data))
} }
const {list} = ThreadWatcher const { list } = ThreadWatcher
$.rmAll(list) $.rmAll(list)
$.add(list, nodes) $.add(list, nodes)
@ -680,7 +680,7 @@ var ThreadWatcher = {
refresh() { refresh() {
ThreadWatcher.build() ThreadWatcher.build()
g.threads.forEach(function(thread) { g.threads.forEach(function (thread) {
const isWatched = ThreadWatcher.isWatched(thread) const isWatched = ThreadWatcher.isWatched(thread)
if (thread.OP) { if (thread.OP) {
for (const post of [thread.OP, ...Array.from(thread.OP.clones)]) { for (const post of [thread.OP, ...Array.from(thread.OP.clones)]) {
@ -694,7 +694,7 @@ var ThreadWatcher = {
}) })
if (Conf['Pin Watched Threads']) { if (Conf['Pin Watched Threads']) {
return $.event('SortIndex', {deferred: Conf['Index Mode'] !== 'catalog'}) return $.event('SortIndex', { deferred: Conf['Index Mode'] !== 'catalog' })
} }
}, },
@ -706,7 +706,7 @@ var ThreadWatcher = {
update(siteID, boardID, threadID, newData) { update(siteID, boardID, threadID, newData) {
let data, key, line, val let data, key, line, val
if (!(data = ThreadWatcher.db?.get({siteID, boardID, threadID}))) { return } if (!(data = ThreadWatcher.db?.get({ siteID, boardID, threadID }))) { return }
if (newData.isDead && Conf['Auto Prune']) { if (newData.isDead && Conf['Auto Prune']) {
ThreadWatcher.rm(siteID, boardID, threadID) ThreadWatcher.rm(siteID, boardID, threadID)
return return
@ -724,7 +724,7 @@ var ThreadWatcher = {
let n = 0 let n = 0
for (key in newData) { val = newData[key]; if (data[key] !== val) { n++ } } for (key in newData) { val = newData[key]; if (data[key] !== val) { n++ } }
if (!n) { return } if (!n) { return }
ThreadWatcher.db.extend({siteID, boardID, threadID, val: newData}) ThreadWatcher.db.extend({ siteID, boardID, threadID, val: newData })
if (line = $(`#watched-threads > [data-site-i-d='${siteID}'][data-full-i-d='${boardID}.${threadID}']`, ThreadWatcher.dialog)) { if (line = $(`#watched-threads > [data-site-i-d='${siteID}'][data-full-i-d='${boardID}.${threadID}']`, ThreadWatcher.dialog)) {
const newLine = ThreadWatcher.makeLine(siteID, boardID, threadID, data) const newLine = ThreadWatcher.makeLine(siteID, boardID, threadID, data)
$.replace(line, newLine) $.replace(line, newLine)
@ -736,20 +736,20 @@ var ThreadWatcher = {
set404(boardID, threadID, cb) { set404(boardID, threadID, cb) {
let data let data
if (!(data = ThreadWatcher.db?.get({boardID, threadID}))) { return cb() } if (!(data = ThreadWatcher.db?.get({ boardID, threadID }))) { return cb() }
if (Conf['Auto Prune']) { if (Conf['Auto Prune']) {
ThreadWatcher.db.delete({boardID, threadID}) ThreadWatcher.db.delete({ boardID, threadID })
return cb() return cb()
} }
if (data.isDead && !((data.isArchived != null) || (data.page != null) || (data.lastPage != null) || (data.unread != null) || (data.quotingYou != null))) { return cb() } if (data.isDead && !((data.isArchived != null) || (data.page != null) || (data.lastPage != null) || (data.unread != null) || (data.quotingYou != null))) { return cb() }
return ThreadWatcher.db.extend({boardID, threadID, val: {isDead: true, isArchived: undefined, page: undefined, lastPage: undefined, unread: undefined, quotingYou: undefined}}, cb) return ThreadWatcher.db.extend({ boardID, threadID, val: { isDead: true, isArchived: undefined, page: undefined, lastPage: undefined, unread: undefined, quotingYou: undefined } }, cb)
}, },
toggle(thread) { toggle(thread) {
const siteID = g.SITE.ID const siteID = g.SITE.ID
const boardID = thread.board.ID const boardID = thread.board.ID
const threadID = thread.ID const threadID = thread.ID
if (ThreadWatcher.db.get({boardID, threadID})) { if (ThreadWatcher.db.get({ boardID, threadID })) {
return ThreadWatcher.rm(siteID, boardID, threadID) return ThreadWatcher.rm(siteID, boardID, threadID)
} else { } else {
return ThreadWatcher.add(thread) return ThreadWatcher.add(thread)
@ -762,7 +762,7 @@ var ThreadWatcher = {
const boardID = thread.board.ID const boardID = thread.board.ID
const threadID = thread.ID const threadID = thread.ID
if (thread.isDead) { if (thread.isDead) {
if (Conf['Auto Prune'] && ThreadWatcher.db.get({boardID, threadID})) { if (Conf['Auto Prune'] && ThreadWatcher.db.get({ boardID, threadID })) {
ThreadWatcher.rm(siteID, boardID, threadID, cb) ThreadWatcher.rm(siteID, boardID, threadID, cb)
return return
} }
@ -777,9 +777,9 @@ var ThreadWatcher = {
delete oldData.last delete oldData.last
delete oldData.modified delete oldData.modified
$.extend(oldData, data) $.extend(oldData, data)
ThreadWatcher.db.set({boardID, threadID, val: oldData}, cb) ThreadWatcher.db.set({ boardID, threadID, val: oldData }, cb)
ThreadWatcher.refresh() ThreadWatcher.refresh()
const thread = {siteID: g.SITE.ID, boardID, threadID, data, force: true} const thread = { siteID: g.SITE.ID, boardID, threadID, data, force: true }
if (Conf['Show Page'] && !data.isDead) { if (Conf['Show Page'] && !data.isDead) {
return ThreadWatcher.fetchBoard([thread]) return ThreadWatcher.fetchBoard([thread])
} else if (ThreadWatcher.unreadEnabled && Conf['Show Unread Count']) { } else if (ThreadWatcher.unreadEnabled && Conf['Show Unread Count']) {
@ -788,7 +788,7 @@ var ThreadWatcher = {
}, },
rm(siteID, boardID, threadID, cb) { rm(siteID, boardID, threadID, cb) {
ThreadWatcher.db.delete({siteID, boardID, threadID}, cb) ThreadWatcher.db.delete({ siteID, boardID, threadID }, cb)
return ThreadWatcher.refresh() return ThreadWatcher.refresh()
}, },
@ -796,7 +796,7 @@ var ThreadWatcher = {
init() { init() {
if (!Conf['Thread Watcher']) { return } if (!Conf['Thread Watcher']) { return }
const menu = (this.menu = new UI.Menu('thread watcher')) const menu = (this.menu = new UI.Menu('thread watcher'))
$.on($('.menu-button', ThreadWatcher.dialog), 'click', function(e) { $.on($('.menu-button', ThreadWatcher.dialog), 'click', function (e) {
return menu.toggle(e, this, ThreadWatcher) return menu.toggle(e, this, ThreadWatcher)
}) })
return this.addMenuEntries() return this.addMenuEntries()
@ -805,12 +805,12 @@ var ThreadWatcher = {
addHeaderMenuEntry() { addHeaderMenuEntry() {
if (g.VIEW !== 'thread') { return } if (g.VIEW !== 'thread') { return }
const entryEl = $.el('a', const entryEl = $.el('a',
{href: 'javascript:;'}) { href: 'javascript:;' })
Header.menu.addEntry({ Header.menu.addEntry({
el: entryEl, el: entryEl,
order: 60, order: 60,
open() { open() {
const [addClass, rmClass, text] = Array.from(ThreadWatcher.db.get({boardID: g.BOARD.ID, threadID: g.THREADID}) ? const [addClass, rmClass, text] = Array.from(ThreadWatcher.db.get({ boardID: g.BOARD.ID, threadID: g.THREADID }) ?
['unwatch-thread', 'watch-thread', 'Unwatch thread'] ['unwatch-thread', 'watch-thread', 'Unwatch thread']
: :
['watch-thread', 'unwatch-thread', 'Watch thread']) ['watch-thread', 'unwatch-thread', 'Watch thread'])
@ -877,7 +877,7 @@ var ThreadWatcher = {
} }
}) })
for (const {text, title, cb, open} of entries) { for (const { text, title, cb, open } of entries) {
const entry = { const entry = {
el: $.el('a', { el: $.el('a', {
textContent: text, textContent: text,

View File

@ -3,7 +3,7 @@ import DataBoard from "../classes/DataBoard"
import RandomAccessList from "../classes/RandomAccessList" import RandomAccessList from "../classes/RandomAccessList"
import Get from "../General/Get" import Get from "../General/Get"
import Header from "../General/Header" import Header from "../General/Header"
import { Conf, d,g } from "../globals/globals" import { Conf, d, g } from "../globals/globals"
import $ from "../platform/$" import $ from "../platform/$"
import { debounce, SECOND } from "../platform/helpers" import { debounce, SECOND } from "../platform/helpers"
import QuoteYou from "../Quotelinks/QuoteYou" import QuoteYou from "../Quotelinks/QuoteYou"
@ -16,7 +16,7 @@ import ThreadWatcher from "./ThreadWatcher"
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/ */
var Unread = { const Unread = {
init() { init() {
if ((g.VIEW !== 'thread') || ( if ((g.VIEW !== 'thread') || (
!Conf['Unread Count'] && !Conf['Unread Count'] &&
@ -64,7 +64,7 @@ var Unread = {
for (const ID of this.posts.keys) { if (+ID <= Unread.lastReadPost) { Unread.readCount++ } } for (const ID of this.posts.keys) { if (+ID <= Unread.lastReadPost) { Unread.readCount++ } }
$.one(d, '4chanXInitFinished', Unread.ready) $.one(d, '4chanXInitFinished', Unread.ready)
$.on(d, 'PostsInserted', Unread.onUpdate) $.on(d, 'PostsInserted', Unread.onUpdate)
$.on(d, 'ThreadUpdate', function(e) { if (e.detail[404]) { return Unread.update() } }) $.on(d, 'ThreadUpdate', function (e) { if (e.detail[404]) { return Unread.update() } })
const resetLink = $.el('a', { const resetLink = $.el('a', {
href: 'javascript:;', href: 'javascript:;',
className: 'unread-reset', className: 'unread-reset',
@ -98,7 +98,7 @@ var Unread = {
let position = Unread.positionPrev() let position = Unread.positionPrev()
while (position) { while (position) {
const {bottom} = position.data.nodes const { bottom } = position.data.nodes
if (!bottom.getBoundingClientRect().height) { if (!bottom.getBoundingClientRect().height) {
// Don't try to scroll to posts with display: none // Don't try to scroll to posts with display: none
position = position.prev position = position.prev
@ -179,14 +179,14 @@ var Unread = {
} }
}, },
openNotification(post, predicate=' replied to you') { openNotification(post, predicate = ' replied to you') {
if (!Header.areNotificationsEnabled) { return } if (!Header.areNotificationsEnabled) { return }
const notif = new Notification(`${post.info.nameBlock}${predicate}`, { const notif = new Notification(`${post.info.nameBlock}${predicate}`, {
body: post.commentDisplay(), body: post.commentDisplay(),
icon: Favicon.logo icon: Favicon.logo
} }
) )
notif.onclick = function() { notif.onclick = function () {
Header.scrollToIfNeeded(post.nodes.bottom, true) Header.scrollToIfNeeded(post.nodes.bottom, true)
return window.focus() return window.focus()
} }
@ -195,7 +195,7 @@ var Unread = {
}, },
onUpdate() { onUpdate() {
return $.queueTask(function() { // ThreadUpdater may scroll immediately after inserting posts return $.queueTask(function () { // ThreadUpdater may scroll immediately after inserting posts
Unread.setLine() Unread.setLine()
Unread.read() Unread.read()
return Unread.update() return Unread.update()
@ -203,7 +203,7 @@ var Unread = {
}, },
readSinglePost(post) { readSinglePost(post) {
const {ID} = post const { ID } = post
if (!Unread.posts.has(ID)) { return } if (!Unread.posts.has(ID)) { return }
Unread.posts.delete(ID) Unread.posts.delete(ID)
Unread.postsQuotingYou.delete(ID) Unread.postsQuotingYou.delete(ID)
@ -212,7 +212,7 @@ var Unread = {
return Unread.update() return Unread.update()
}, },
read: debounce(100, function(e) { read: debounce(100, function (e) {
// Update the lastReadPost when hidden posts are added to the thread. // Update the lastReadPost when hidden posts are added to the thread.
if (!Unread.posts.size && (Unread.readCount !== Unread.thread.posts.keys.length)) { if (!Unread.posts.size && (Unread.readCount !== Unread.thread.posts.keys.length)) {
Unread.saveLastReadPost() Unread.saveLastReadPost()
@ -222,8 +222,8 @@ var Unread = {
let count = 0 let count = 0
while (Unread.position) { while (Unread.position) {
const {ID, data} = Unread.position const { ID, data } = Unread.position
const {bottom} = data.nodes const { bottom } = data.nodes
if (!!bottom.getBoundingClientRect().height && // post has been hidden if (!!bottom.getBoundingClientRect().height && // post has been hidden
(Header.getBottomOf(bottom) <= -1)) { break } // post is completely read (Header.getBottomOf(bottom) <= -1)) { break } // post is completely read
count++ count++
@ -244,7 +244,7 @@ var Unread = {
} }
}, },
saveLastReadPost: debounce(2 * SECOND, function() { saveLastReadPost: debounce(2 * SECOND, function () {
let ID let ID
$.forceSync('Remember Last Read Post') $.forceSync('Remember Last Read Post')
if (!Conf['Remember Last Read Post'] || !Unread.db) { return } if (!Conf['Remember Last Read Post'] || !Unread.db) { return }
@ -299,7 +299,7 @@ var Unread = {
Unread.saveThreadWatcherCount() Unread.saveThreadWatcherCount()
if (Conf['Unread Favicon'] && (g.SITE.software === 'yotsuba')) { if (Conf['Unread Favicon'] && (g.SITE.software === 'yotsuba')) {
const {isDead} = Unread.thread const { isDead } = Unread.thread
return Favicon.set(( return Favicon.set((
countQuotingYou ? countQuotingYou ?
(isDead ? 'unreadDeadY' : 'unreadY') (isDead ? 'unreadDeadY' : 'unreadY')
@ -312,7 +312,7 @@ var Unread = {
} }
}, },
saveThreadWatcherCount: debounce(2 * SECOND, function() { saveThreadWatcherCount: debounce(2 * SECOND, function () {
$.forceSync('Remember Last Read Post') $.forceSync('Remember Last Read Post')
if (Conf['Remember Last Read Post'] && (!Unread.thread.isDead || Unread.thread.isArchived)) { if (Conf['Remember Last Read Post'] && (!Unread.thread.isDead || Unread.thread.isArchived)) {
let posts let posts

View File

@ -3,7 +3,7 @@ import DataBoard from "../classes/DataBoard"
import Get from "../General/Get" import Get from "../General/Get"
import Header from "../General/Header" import Header from "../General/Header"
import Index from "../General/Index" import Index from "../General/Index"
import { Conf, d,g } from "../globals/globals" import { Conf, d, g } from "../globals/globals"
import ExpandThread from "../Miscellaneous/ExpandThread" import ExpandThread from "../Miscellaneous/ExpandThread"
import $ from "../platform/$" import $ from "../platform/$"
import { dict } from "../platform/helpers" import { dict } from "../platform/helpers"
@ -16,7 +16,7 @@ import ThreadWatcher from "./ThreadWatcher"
* DS205: Consider reworking code to avoid use of IIFEs * DS205: Consider reworking code to avoid use of IIFEs
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/ */
var UnreadIndex = { const UnreadIndex = {
lastReadPost: dict(), lastReadPost: dict(),
hr: dict(), hr: dict(),
markReadLink: dict(), markReadLink: dict(),
@ -70,7 +70,7 @@ var UnreadIndex = {
}, },
sync() { sync() {
return g.threads.forEach(function(thread) { return g.threads.forEach(function (thread) {
const lastReadPost = UnreadIndex.db.get({ const lastReadPost = UnreadIndex.db.get({
boardID: thread.board.ID, boardID: thread.board.ID,
threadID: thread.ID threadID: thread.ID
@ -90,7 +90,7 @@ var UnreadIndex = {
let repliesShown = 0 let repliesShown = 0
let repliesRead = 0 let repliesRead = 0
let firstUnread = null let firstUnread = null
thread.posts.forEach(function(post) { thread.posts.forEach(function (post) {
if (post.isReply && thread.nodes.root.contains(post.nodes.root)) { if (post.isReply && thread.nodes.root.contains(post.nodes.root)) {
repliesShown++ repliesShown++
if (post.ID <= lastReadPost) { if (post.ID <= lastReadPost) {
@ -105,7 +105,7 @@ var UnreadIndex = {
if (firstUnread && (repliesRead || ((lastReadPost === thread.OP.ID) && (!$(g.SITE.selectors.summary, thread.nodes.root) || thread.ID in ExpandThread.statuses)))) { if (firstUnread && (repliesRead || ((lastReadPost === thread.OP.ID) && (!$(g.SITE.selectors.summary, thread.nodes.root) || thread.ID in ExpandThread.statuses)))) {
if (!hr) { if (!hr) {
hr = (UnreadIndex.hr[thread.fullID] = $.el('hr', hr = (UnreadIndex.hr[thread.fullID] = $.el('hr',
{className: 'unread-line'})) { className: 'unread-line' }))
} }
$.before(firstUnread.nodes.root, hr) $.before(firstUnread.nodes.root, hr)
} else { } else {