mirror of
https://github.com/LalleSX/4chan-XZ.git
synced 2026-01-30 09:48:12 +01:00
var to const
This commit is contained in:
parent
69051d6095
commit
5183de55b6
@ -30,13 +30,13 @@ import UnreadIndex from './UnreadIndex'
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
||||
*/
|
||||
|
||||
var ThreadWatcher = {
|
||||
const ThreadWatcher = {
|
||||
init() {
|
||||
let sc
|
||||
if (!(this.enabled = Conf['Thread Watcher'])) { return }
|
||||
|
||||
this.shortcut = (sc = $.el('a', {
|
||||
id: 'watcher-link',
|
||||
id: 'watcher-link',
|
||||
textContent: 'Watcher',
|
||||
title: 'Thread Watcher',
|
||||
href: 'javascript:;',
|
||||
@ -44,17 +44,17 @@ var ThreadWatcher = {
|
||||
}
|
||||
))
|
||||
|
||||
this.db = new DataBoard('watchedThreads', this.refresh, true)
|
||||
this.dbLM = new DataBoard('watcherLastModified', null, true)
|
||||
this.db = new DataBoard('watchedThreads', this.refresh, true)
|
||||
this.dbLM = new DataBoard('watcherLastModified', null, true)
|
||||
this.dialog = UI.dialog('thread-watcher', { innerHTML: ThreadWatcherPage })
|
||||
this.status = $('#watcher-status', this.dialog)
|
||||
this.list = this.dialog.lastElementChild
|
||||
this.list = this.dialog.lastElementChild
|
||||
this.refreshButton = $('.refresh', this.dialog)
|
||||
this.closeButton = $('.move > .close', this.dialog)
|
||||
this.unreaddb = Unread.db || UnreadIndex.db || new DataBoard('lastReadPosts')
|
||||
this.unreadEnabled = Conf['Remember Last Read Post']
|
||||
|
||||
$.on(d, 'QRPostSuccessful', this.cb.post)
|
||||
$.on(d, 'QRPostSuccessful', this.cb.post)
|
||||
$.on(sc, 'click', this.toggleWatcher)
|
||||
$.on(this.refreshButton, 'click', this.buttonFetchAll)
|
||||
$.on(this.closeButton, 'click', this.toggleWatcher)
|
||||
@ -88,19 +88,19 @@ var ThreadWatcher = {
|
||||
if (Conf['Menu'] && Index.enabled) {
|
||||
Menu.menu.addEntry({
|
||||
el: $.el('a', {
|
||||
href: 'javascript:;',
|
||||
href: 'javascript:;',
|
||||
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,
|
||||
open({thread}) {
|
||||
open({ thread }) {
|
||||
if (Conf['Index Mode'] !== 'catalog') { return false }
|
||||
this.el.firstElementChild.textContent = ThreadWatcher.isWatched(thread) ?
|
||||
'Unwatch'
|
||||
:
|
||||
:
|
||||
'Watch'
|
||||
if (this.cb) { $.off(this.el, 'click', this.cb) }
|
||||
this.cb = function() {
|
||||
this.cb = function () {
|
||||
$.event('CloseMenu')
|
||||
return ThreadWatcher.toggle(thread)
|
||||
}
|
||||
@ -114,20 +114,20 @@ var ThreadWatcher = {
|
||||
|
||||
Callbacks.Post.push({
|
||||
name: 'Thread Watcher',
|
||||
cb: this.node
|
||||
cb: this.node
|
||||
})
|
||||
return Callbacks.CatalogThread.push({
|
||||
name: 'Thread Watcher',
|
||||
cb: this.catalogNode
|
||||
cb: this.catalogNode
|
||||
})
|
||||
},
|
||||
|
||||
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) {
|
||||
return !!ThreadWatcher.db?.get({boardID, threadID})
|
||||
return !!ThreadWatcher.db?.get({ boardID, threadID })
|
||||
},
|
||||
|
||||
setToggler(toggler, isWatched) {
|
||||
@ -151,14 +151,14 @@ var ThreadWatcher = {
|
||||
const siteID = g.SITE.ID
|
||||
const boardID = this.board.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)
|
||||
$.on(toggler, 'click', ThreadWatcher.cb.toggle)
|
||||
// Add missing excerpt for threads added by Auto Watch
|
||||
if (data && (data.excerpt == null)) {
|
||||
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() {
|
||||
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) {
|
||||
ThreadWatcher.db.delete({siteID, boardID, threadID})
|
||||
ThreadWatcher.db.delete({ siteID, boardID, threadID })
|
||||
}
|
||||
}
|
||||
ThreadWatcher.refresh()
|
||||
return $.event('CloseMenu')
|
||||
},
|
||||
dismiss() {
|
||||
for (const {siteID, boardID, threadID, data} of ThreadWatcher.getAll()) {
|
||||
for (const { siteID, boardID, threadID, data } of ThreadWatcher.getAll()) {
|
||||
if (data.quotingYou) {
|
||||
ThreadWatcher.update(siteID, boardID, threadID, {dismiss: data.quotingYou || 0})
|
||||
ThreadWatcher.update(siteID, boardID, threadID, { dismiss: data.quotingYou || 0 })
|
||||
}
|
||||
}
|
||||
return $.event('CloseMenu')
|
||||
},
|
||||
toggle() {
|
||||
const {thread} = Get.postFromNode(this)
|
||||
const { thread } = Get.postFromNode(this)
|
||||
return ThreadWatcher.toggle(thread)
|
||||
},
|
||||
rm() {
|
||||
const {siteID} = this.parentNode.dataset
|
||||
const { siteID } = this.parentNode.dataset
|
||||
const [boardID, threadID] = Array.from(this.parentNode.dataset.fullID.split('.'))
|
||||
return ThreadWatcher.rm(siteID, boardID, +threadID)
|
||||
},
|
||||
post(e) {
|
||||
const {boardID, threadID, postID} = e.detail
|
||||
const { boardID, threadID, postID } = e.detail
|
||||
const cb = PostRedirect.delay()
|
||||
if (postID === threadID) {
|
||||
if (Conf['Auto Watch']) {
|
||||
@ -243,8 +243,8 @@ var ThreadWatcher = {
|
||||
}
|
||||
},
|
||||
onIndexUpdate(e) {
|
||||
const {db} = ThreadWatcher
|
||||
const siteID = g.SITE.ID
|
||||
const { db } = ThreadWatcher
|
||||
const siteID = g.SITE.ID
|
||||
const boardID = g.BOARD.ID
|
||||
let nKilled = 0
|
||||
for (var threadID in db.data[siteID].boards[boardID]) {
|
||||
@ -253,10 +253,10 @@ var ThreadWatcher = {
|
||||
if (!data?.isDead && !e.detail.threads.includes(`${boardID}.${threadID}`)) {
|
||||
if (!e.detail.threads.some(fullID => +fullID.split('.')[1] > threadID)) { continue }
|
||||
if (Conf['Auto Prune'] || !(data && (typeof data === 'object'))) { // corrupt data
|
||||
db.delete({boardID, threadID})
|
||||
db.delete({ boardID, threadID })
|
||||
nKilled++
|
||||
} else {
|
||||
ThreadWatcher.fetchStatus({siteID, boardID, threadID, data})
|
||||
ThreadWatcher.fetchStatus({ siteID, boardID, threadID, data })
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -271,14 +271,14 @@ var ThreadWatcher = {
|
||||
},
|
||||
|
||||
requests: [],
|
||||
fetched: 0,
|
||||
fetched: 0,
|
||||
|
||||
fetch(url, {siteID, force}, args, cb) {
|
||||
fetch(url, { siteID, force }, args, cb) {
|
||||
if (ThreadWatcher.requests.length === 0) {
|
||||
ThreadWatcher.status.textContent = '...'
|
||||
$.addClass(ThreadWatcher.refreshButton, 'fa-spin')
|
||||
}
|
||||
const onloadend = function() {
|
||||
const onloadend = function () {
|
||||
if (this.finished) { return }
|
||||
this.finished = true
|
||||
ThreadWatcher.fetched++
|
||||
@ -326,13 +326,13 @@ var ThreadWatcher = {
|
||||
const boards = ThreadWatcher.dbLM.data[siteID]
|
||||
for (const boardID in boards.boards) {
|
||||
const data = boards.boards[boardID]
|
||||
if (ThreadWatcher.db.get({siteID, boardID})) {
|
||||
if (ThreadWatcher.db.get({ siteID, boardID })) {
|
||||
for (const url in data) {
|
||||
const date = data[url]
|
||||
lm[url] = date
|
||||
}
|
||||
} else {
|
||||
ThreadWatcher.dbLM.delete({siteID, boardID})
|
||||
ThreadWatcher.dbLM.delete({ siteID, boardID })
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -342,7 +342,7 @@ var ThreadWatcher = {
|
||||
let middle
|
||||
clearTimeout(ThreadWatcher.timeout)
|
||||
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 now = Date.now()
|
||||
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 = '...'
|
||||
$.addClass(ThreadWatcher.refreshButton, 'fa-spin')
|
||||
ThreadWatcher.syncing = true
|
||||
const dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter(x => x)
|
||||
let n = 0
|
||||
return dbs.map((dbi) =>
|
||||
dbi.forceSync(function() {
|
||||
dbi.forceSync(function () {
|
||||
if ((++n) === dbs.length) {
|
||||
let middle
|
||||
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.
|
||||
// Occasionally check replies field of catalog.json to find these posts.
|
||||
let middle1
|
||||
const {db} = ThreadWatcher
|
||||
const { db } = ThreadWatcher
|
||||
const now = Date.now()
|
||||
const deep = !(now - (2 * HOUR) < ((middle1 = db.data.lastChecked2 || 0)) && middle1 <= now)
|
||||
const boards = ThreadWatcher.getAll(true)
|
||||
@ -396,27 +396,27 @@ var ThreadWatcher = {
|
||||
if (!board.some(thread => !thread.data.isDead)) { return }
|
||||
let force = false
|
||||
for (const thread of board) {
|
||||
const {data} = thread
|
||||
const { data } = thread
|
||||
if (!data.isDead && (data.last !== -1)) {
|
||||
if (Conf['Show Page'] && (data.page == null)) { 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]
|
||||
if (!site) { return }
|
||||
const urlF = deep && site.threadModTimeIgnoresSage ? 'catalogJSON' : 'threadsListJSON'
|
||||
const url = site.urls[urlF]?.({siteID, boardID})
|
||||
const url = site.urls[urlF]?.({ siteID, boardID })
|
||||
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) {
|
||||
let page, thread
|
||||
if (this.status !== 200) { return }
|
||||
const {siteID, boardID} = board[0]
|
||||
const { siteID, boardID } = board[0]
|
||||
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()
|
||||
let pageLength = 0
|
||||
let nThreads = 0
|
||||
@ -444,16 +444,16 @@ var ThreadWatcher = {
|
||||
}
|
||||
}
|
||||
for (thread of board) {
|
||||
const {threadID, data} = thread
|
||||
const { threadID, data } = thread
|
||||
if (threads[threadID]) {
|
||||
var index, modified, replies;
|
||||
({page, index, modified, replies} = threads[threadID])
|
||||
({ page, index, modified, replies } = threads[threadID])
|
||||
if (Conf['Show Page']) {
|
||||
const lastPage = g.sites[siteID].isPrunedByAge?.({siteID, boardID}) ?
|
||||
const lastPage = g.sites[siteID].isPrunedByAge?.({ siteID, boardID }) ?
|
||||
threadID === oldest
|
||||
:
|
||||
:
|
||||
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 ((modified !== data.modified) || ((replies != null) && (replies !== data.replies))) {
|
||||
@ -468,22 +468,22 @@ var ThreadWatcher = {
|
||||
},
|
||||
|
||||
fetchStatus(thread) {
|
||||
const {siteID, boardID, threadID, data, force} = thread
|
||||
const url = g.sites[siteID]?.urls.threadJSON?.({siteID, boardID, threadID})
|
||||
const { siteID, boardID, threadID, data, force } = thread
|
||||
const url = g.sites[siteID]?.urls.threadJSON?.({ siteID, boardID, threadID })
|
||||
if (!url) { return }
|
||||
if (data.isDead && !force) { return }
|
||||
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) {
|
||||
let isDead, last
|
||||
let {siteID, boardID, threadID, data, newData, force} = thread
|
||||
let { siteID, boardID, threadID, data, newData, force } = thread
|
||||
const site = g.sites[siteID]
|
||||
if ((this.status === 200) && this.response) {
|
||||
let isArchived
|
||||
last = this.response.posts[this.response.posts.length-1].no
|
||||
const replies = this.response.posts.length-1
|
||||
last = this.response.posts[this.response.posts.length - 1].no
|
||||
const replies = this.response.posts.length - 1
|
||||
isDead = (isArchived = !!(this.response.posts[0].archived || isArchiveURL))
|
||||
if (isDead && Conf['Auto Prune']) {
|
||||
ThreadWatcher.rm(siteID, boardID, threadID)
|
||||
@ -492,14 +492,14 @@ var ThreadWatcher = {
|
||||
|
||||
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 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) {
|
||||
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
|
||||
if (!Conf['Require OP Quote Link'] && youOP) {
|
||||
@ -511,9 +511,9 @@ var ThreadWatcher = {
|
||||
while (match = regexp.exec(postObj.com)) {
|
||||
if (QuoteYou.db.get({
|
||||
siteID,
|
||||
boardID: match[1] ? encodeURIComponent(match[1]) : boardID,
|
||||
boardID: match[1] ? encodeURIComponent(match[1]) : boardID,
|
||||
threadID: match[2] || threadID,
|
||||
postID: match[3] || match[2] || threadID
|
||||
postID: match[3] || match[2] || threadID
|
||||
})) {
|
||||
quotesYou = true
|
||||
break
|
||||
@ -522,7 +522,7 @@ var ThreadWatcher = {
|
||||
}
|
||||
|
||||
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++
|
||||
@ -530,17 +530,17 @@ var ThreadWatcher = {
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
} 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) {
|
||||
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)) {
|
||||
return ThreadWatcher.update(siteID, boardID, threadID, {last: -1})
|
||||
return ThreadWatcher.update(siteID, boardID, threadID, { last: -1 })
|
||||
} 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) {
|
||||
const data = threads[threadID]
|
||||
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)
|
||||
|
||||
let {excerpt, isArchived} = data
|
||||
let { excerpt, isArchived } = data
|
||||
if (!excerpt) { excerpt = `/${boardID}/ - No.${threadID}` }
|
||||
if (Conf['Show Site Prefix']) { excerpt = ThreadWatcher.prefixes[siteID] + excerpt }
|
||||
|
||||
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,
|
||||
className: 'watcher-link'
|
||||
}
|
||||
@ -635,7 +635,7 @@ var ThreadWatcher = {
|
||||
|
||||
setPrefixes(threads) {
|
||||
const prefixes = dict()
|
||||
for (const {siteID} of threads) {
|
||||
for (const { siteID } of threads) {
|
||||
if (siteID in prefixes) { continue }
|
||||
let len = 0
|
||||
let prefix = ''
|
||||
@ -662,15 +662,15 @@ var ThreadWatcher = {
|
||||
const nodes = []
|
||||
const threads = ThreadWatcher.getAll()
|
||||
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
|
||||
var thread
|
||||
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))
|
||||
}
|
||||
const {list} = ThreadWatcher
|
||||
const { list } = ThreadWatcher
|
||||
$.rmAll(list)
|
||||
$.add(list, nodes)
|
||||
|
||||
@ -680,7 +680,7 @@ var ThreadWatcher = {
|
||||
refresh() {
|
||||
ThreadWatcher.build()
|
||||
|
||||
g.threads.forEach(function(thread) {
|
||||
g.threads.forEach(function (thread) {
|
||||
const isWatched = ThreadWatcher.isWatched(thread)
|
||||
if (thread.OP) {
|
||||
for (const post of [thread.OP, ...Array.from(thread.OP.clones)]) {
|
||||
@ -694,7 +694,7 @@ var ThreadWatcher = {
|
||||
})
|
||||
|
||||
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) {
|
||||
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']) {
|
||||
ThreadWatcher.rm(siteID, boardID, threadID)
|
||||
return
|
||||
@ -724,7 +724,7 @@ var ThreadWatcher = {
|
||||
let n = 0
|
||||
for (key in newData) { val = newData[key]; if (data[key] !== val) { n++ } }
|
||||
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)) {
|
||||
const newLine = ThreadWatcher.makeLine(siteID, boardID, threadID, data)
|
||||
$.replace(line, newLine)
|
||||
@ -736,20 +736,20 @@ var ThreadWatcher = {
|
||||
|
||||
set404(boardID, threadID, cb) {
|
||||
let data
|
||||
if (!(data = ThreadWatcher.db?.get({boardID, threadID}))) { return cb() }
|
||||
if (!(data = ThreadWatcher.db?.get({ boardID, threadID }))) { return cb() }
|
||||
if (Conf['Auto Prune']) {
|
||||
ThreadWatcher.db.delete({boardID, threadID})
|
||||
ThreadWatcher.db.delete({ boardID, threadID })
|
||||
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) {
|
||||
const siteID = g.SITE.ID
|
||||
const boardID = thread.board.ID
|
||||
const siteID = g.SITE.ID
|
||||
const boardID = thread.board.ID
|
||||
const threadID = thread.ID
|
||||
if (ThreadWatcher.db.get({boardID, threadID})) {
|
||||
if (ThreadWatcher.db.get({ boardID, threadID })) {
|
||||
return ThreadWatcher.rm(siteID, boardID, threadID)
|
||||
} else {
|
||||
return ThreadWatcher.add(thread)
|
||||
@ -757,12 +757,12 @@ var ThreadWatcher = {
|
||||
},
|
||||
|
||||
add(thread, cb) {
|
||||
const data = {}
|
||||
const siteID = g.SITE.ID
|
||||
const boardID = thread.board.ID
|
||||
const data = {}
|
||||
const siteID = g.SITE.ID
|
||||
const boardID = thread.board.ID
|
||||
const threadID = thread.ID
|
||||
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)
|
||||
return
|
||||
}
|
||||
@ -777,9 +777,9 @@ var ThreadWatcher = {
|
||||
delete oldData.last
|
||||
delete oldData.modified
|
||||
$.extend(oldData, data)
|
||||
ThreadWatcher.db.set({boardID, threadID, val: oldData}, cb)
|
||||
ThreadWatcher.db.set({ boardID, threadID, val: oldData }, cb)
|
||||
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) {
|
||||
return ThreadWatcher.fetchBoard([thread])
|
||||
} else if (ThreadWatcher.unreadEnabled && Conf['Show Unread Count']) {
|
||||
@ -788,7 +788,7 @@ var ThreadWatcher = {
|
||||
},
|
||||
|
||||
rm(siteID, boardID, threadID, cb) {
|
||||
ThreadWatcher.db.delete({siteID, boardID, threadID}, cb)
|
||||
ThreadWatcher.db.delete({ siteID, boardID, threadID }, cb)
|
||||
return ThreadWatcher.refresh()
|
||||
},
|
||||
|
||||
@ -796,7 +796,7 @@ var ThreadWatcher = {
|
||||
init() {
|
||||
if (!Conf['Thread Watcher']) { return }
|
||||
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 this.addMenuEntries()
|
||||
@ -805,14 +805,14 @@ var ThreadWatcher = {
|
||||
addHeaderMenuEntry() {
|
||||
if (g.VIEW !== 'thread') { return }
|
||||
const entryEl = $.el('a',
|
||||
{href: 'javascript:;'})
|
||||
{ href: 'javascript:;' })
|
||||
Header.menu.addEntry({
|
||||
el: entryEl,
|
||||
order: 60,
|
||||
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']
|
||||
:
|
||||
:
|
||||
['watch-thread', 'unwatch-thread', 'Watch thread'])
|
||||
$.addClass(entryEl, addClass)
|
||||
$.rmClass(entryEl, rmClass)
|
||||
@ -877,7 +877,7 @@ var ThreadWatcher = {
|
||||
}
|
||||
})
|
||||
|
||||
for (const {text, title, cb, open} of entries) {
|
||||
for (const { text, title, cb, open } of entries) {
|
||||
const entry = {
|
||||
el: $.el('a', {
|
||||
textContent: text,
|
||||
|
||||
@ -3,7 +3,7 @@ import DataBoard from "../classes/DataBoard"
|
||||
import RandomAccessList from "../classes/RandomAccessList"
|
||||
import Get from "../General/Get"
|
||||
import Header from "../General/Header"
|
||||
import { Conf, d,g } from "../globals/globals"
|
||||
import { Conf, d, g } from "../globals/globals"
|
||||
import $ from "../platform/$"
|
||||
import { debounce, SECOND } from "../platform/helpers"
|
||||
import QuoteYou from "../Quotelinks/QuoteYou"
|
||||
@ -16,7 +16,7 @@ import ThreadWatcher from "./ThreadWatcher"
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
||||
*/
|
||||
var Unread = {
|
||||
const Unread = {
|
||||
init() {
|
||||
if ((g.VIEW !== 'thread') || (
|
||||
!Conf['Unread Count'] &&
|
||||
@ -44,18 +44,18 @@ var Unread = {
|
||||
|
||||
Callbacks.Thread.push({
|
||||
name: 'Unread',
|
||||
cb: this.node
|
||||
cb: this.node
|
||||
})
|
||||
|
||||
return Callbacks.Post.push({
|
||||
name: 'Unread',
|
||||
cb: this.addPost
|
||||
cb: this.addPost
|
||||
})
|
||||
},
|
||||
|
||||
node() {
|
||||
Unread.thread = this
|
||||
Unread.title = d.title
|
||||
Unread.title = d.title
|
||||
Unread.lastReadPost = Unread.db?.get({
|
||||
boardID: this.board.ID,
|
||||
threadID: this.ID
|
||||
@ -63,8 +63,8 @@ var Unread = {
|
||||
Unread.readCount = 0
|
||||
for (const ID of this.posts.keys) { if (+ID <= Unread.lastReadPost) { Unread.readCount++ } }
|
||||
$.one(d, '4chanXInitFinished', Unread.ready)
|
||||
$.on(d, 'PostsInserted', Unread.onUpdate)
|
||||
$.on(d, 'ThreadUpdate', function(e) { if (e.detail[404]) { return Unread.update() } })
|
||||
$.on(d, 'PostsInserted', Unread.onUpdate)
|
||||
$.on(d, 'ThreadUpdate', function (e) { if (e.detail[404]) { return Unread.update() } })
|
||||
const resetLink = $.el('a', {
|
||||
href: 'javascript:;',
|
||||
className: 'unread-reset',
|
||||
@ -84,7 +84,7 @@ var Unread = {
|
||||
Unread.read()
|
||||
Unread.update()
|
||||
$.on(d, 'scroll visibilitychange', Unread.read)
|
||||
if (Conf['Unread Line']) { return $.on(d, 'visibilitychange', Unread.setLine) }
|
||||
if (Conf['Unread Line']) { return $.on(d, 'visibilitychange', Unread.setLine) }
|
||||
},
|
||||
|
||||
positionPrev() {
|
||||
@ -98,7 +98,7 @@ var Unread = {
|
||||
|
||||
let position = Unread.positionPrev()
|
||||
while (position) {
|
||||
const {bottom} = position.data.nodes
|
||||
const { bottom } = position.data.nodes
|
||||
if (!bottom.getBoundingClientRect().height) {
|
||||
// Don't try to scroll to posts with display: none
|
||||
position = position.prev
|
||||
@ -123,9 +123,9 @@ var Unread = {
|
||||
$.forceSync('Remember Last Read Post')
|
||||
if (Conf['Remember Last Read Post'] && (!Unread.thread.isDead || Unread.thread.isArchived)) {
|
||||
Unread.db.set({
|
||||
boardID: Unread.thread.board.ID,
|
||||
boardID: Unread.thread.board.ID,
|
||||
threadID: Unread.thread.ID,
|
||||
val: 0
|
||||
val: 0
|
||||
})
|
||||
}
|
||||
|
||||
@ -179,23 +179,23 @@ var Unread = {
|
||||
}
|
||||
},
|
||||
|
||||
openNotification(post, predicate=' replied to you') {
|
||||
openNotification(post, predicate = ' replied to you') {
|
||||
if (!Header.areNotificationsEnabled) { return }
|
||||
const notif = new Notification(`${post.info.nameBlock}${predicate}`, {
|
||||
body: post.commentDisplay(),
|
||||
icon: Favicon.logo
|
||||
}
|
||||
)
|
||||
notif.onclick = function() {
|
||||
notif.onclick = function () {
|
||||
Header.scrollToIfNeeded(post.nodes.bottom, true)
|
||||
return window.focus()
|
||||
}
|
||||
return notif.onshow = () => setTimeout(() => notif.close()
|
||||
, 7 * SECOND)
|
||||
, 7 * SECOND)
|
||||
},
|
||||
|
||||
onUpdate() {
|
||||
return $.queueTask(function() { // ThreadUpdater may scroll immediately after inserting posts
|
||||
return $.queueTask(function () { // ThreadUpdater may scroll immediately after inserting posts
|
||||
Unread.setLine()
|
||||
Unread.read()
|
||||
return Unread.update()
|
||||
@ -203,7 +203,7 @@ var Unread = {
|
||||
},
|
||||
|
||||
readSinglePost(post) {
|
||||
const {ID} = post
|
||||
const { ID } = post
|
||||
if (!Unread.posts.has(ID)) { return }
|
||||
Unread.posts.delete(ID)
|
||||
Unread.postsQuotingYou.delete(ID)
|
||||
@ -212,7 +212,7 @@ var Unread = {
|
||||
return Unread.update()
|
||||
},
|
||||
|
||||
read: debounce(100, function(e) {
|
||||
read: debounce(100, function (e) {
|
||||
// Update the lastReadPost when hidden posts are added to the thread.
|
||||
if (!Unread.posts.size && (Unread.readCount !== Unread.thread.posts.keys.length)) {
|
||||
Unread.saveLastReadPost()
|
||||
@ -222,8 +222,8 @@ var Unread = {
|
||||
|
||||
let count = 0
|
||||
while (Unread.position) {
|
||||
const {ID, data} = Unread.position
|
||||
const {bottom} = data.nodes
|
||||
const { ID, data } = Unread.position
|
||||
const { bottom } = data.nodes
|
||||
if (!!bottom.getBoundingClientRect().height && // post has been hidden
|
||||
(Header.getBottomOf(bottom) <= -1)) { break } // post is completely read
|
||||
count++
|
||||
@ -244,7 +244,7 @@ var Unread = {
|
||||
}
|
||||
},
|
||||
|
||||
saveLastReadPost: debounce(2 * SECOND, function() {
|
||||
saveLastReadPost: debounce(2 * SECOND, function () {
|
||||
let ID
|
||||
$.forceSync('Remember Last Read Post')
|
||||
if (!Conf['Remember Last Read Post'] || !Unread.db) { return }
|
||||
@ -259,9 +259,9 @@ var Unread = {
|
||||
}
|
||||
if (Unread.thread.isDead && !Unread.thread.isArchived) { return }
|
||||
return Unread.db.set({
|
||||
boardID: Unread.thread.board.ID,
|
||||
boardID: Unread.thread.board.ID,
|
||||
threadID: Unread.thread.ID,
|
||||
val: Unread.lastReadPost
|
||||
val: Unread.lastReadPost
|
||||
})
|
||||
}),
|
||||
|
||||
@ -291,7 +291,7 @@ var Unread = {
|
||||
const titleCount = count || !Conf['Hide Unread Count at (0)'] ? `(${count}) ` : ''
|
||||
const titleDead = Unread.thread.isDead ?
|
||||
Unread.title.replace('-', (Unread.thread.isArchived ? '- Archived -' : '- 404 -'))
|
||||
:
|
||||
:
|
||||
Unread.title
|
||||
d.title = `${titleQuotingYou}${titleCount}${titleDead}`
|
||||
}
|
||||
@ -299,20 +299,20 @@ var Unread = {
|
||||
Unread.saveThreadWatcherCount()
|
||||
|
||||
if (Conf['Unread Favicon'] && (g.SITE.software === 'yotsuba')) {
|
||||
const {isDead} = Unread.thread
|
||||
const { isDead } = Unread.thread
|
||||
return Favicon.set((
|
||||
countQuotingYou ?
|
||||
(isDead ? 'unreadDeadY' : 'unreadY')
|
||||
: count ?
|
||||
(isDead ? 'unreadDead' : 'unread')
|
||||
:
|
||||
(isDead ? 'dead' : 'default')
|
||||
: count ?
|
||||
(isDead ? 'unreadDead' : 'unread')
|
||||
:
|
||||
(isDead ? 'dead' : 'default')
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
saveThreadWatcherCount: debounce(2 * SECOND, function() {
|
||||
saveThreadWatcherCount: debounce(2 * SECOND, function () {
|
||||
$.forceSync('Remember Last Read Post')
|
||||
if (Conf['Remember Last Read Post'] && (!Unread.thread.isDead || Unread.thread.isArchived)) {
|
||||
let posts
|
||||
|
||||
@ -3,7 +3,7 @@ import DataBoard from "../classes/DataBoard"
|
||||
import Get from "../General/Get"
|
||||
import Header from "../General/Header"
|
||||
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 $ from "../platform/$"
|
||||
import { dict } from "../platform/helpers"
|
||||
@ -16,9 +16,9 @@ import ThreadWatcher from "./ThreadWatcher"
|
||||
* DS205: Consider reworking code to avoid use of IIFEs
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
||||
*/
|
||||
var UnreadIndex = {
|
||||
const UnreadIndex = {
|
||||
lastReadPost: dict(),
|
||||
hr: dict(),
|
||||
hr: dict(),
|
||||
markReadLink: dict(),
|
||||
|
||||
init() {
|
||||
@ -29,7 +29,7 @@ var UnreadIndex = {
|
||||
|
||||
Callbacks.Thread.push({
|
||||
name: 'Unread Line in Index',
|
||||
cb: this.node
|
||||
cb: this.node
|
||||
})
|
||||
|
||||
$.on(d, 'IndexRefreshInternal', this.onIndexRefresh)
|
||||
@ -70,7 +70,7 @@ var UnreadIndex = {
|
||||
},
|
||||
|
||||
sync() {
|
||||
return g.threads.forEach(function(thread) {
|
||||
return g.threads.forEach(function (thread) {
|
||||
const lastReadPost = UnreadIndex.db.get({
|
||||
boardID: thread.board.ID,
|
||||
threadID: thread.ID
|
||||
@ -90,7 +90,7 @@ var UnreadIndex = {
|
||||
let repliesShown = 0
|
||||
let repliesRead = 0
|
||||
let firstUnread = null
|
||||
thread.posts.forEach(function(post) {
|
||||
thread.posts.forEach(function (post) {
|
||||
if (post.isReply && thread.nodes.root.contains(post.nodes.root)) {
|
||||
repliesShown++
|
||||
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 (!hr) {
|
||||
hr = (UnreadIndex.hr[thread.fullID] = $.el('hr',
|
||||
{className: 'unread-line'}))
|
||||
{ className: 'unread-line' }))
|
||||
}
|
||||
$.before(firstUnread.nodes.root, hr)
|
||||
} else {
|
||||
@ -114,10 +114,10 @@ var UnreadIndex = {
|
||||
|
||||
const hasUnread = repliesShown ?
|
||||
firstUnread || !repliesRead
|
||||
: Index.enabled ?
|
||||
thread.lastPost > lastReadPost
|
||||
:
|
||||
thread.OP.ID > lastReadPost
|
||||
: Index.enabled ?
|
||||
thread.lastPost > lastReadPost
|
||||
:
|
||||
thread.OP.ID > lastReadPost
|
||||
thread.nodes.root.classList.toggle('unread-thread', hasUnread)
|
||||
|
||||
let link = UnreadIndex.markReadLink[thread.fullID]
|
||||
@ -141,9 +141,9 @@ var UnreadIndex = {
|
||||
const thread = Get.threadFromNode(this)
|
||||
UnreadIndex.lastReadPost[thread.fullID] = thread.lastPost
|
||||
UnreadIndex.db.set({
|
||||
boardID: thread.board.ID,
|
||||
boardID: thread.board.ID,
|
||||
threadID: thread.ID,
|
||||
val: thread.lastPost
|
||||
val: thread.lastPost
|
||||
})
|
||||
$.rm(UnreadIndex.hr[thread.fullID])
|
||||
thread.nodes.root.classList.remove('unread-thread')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user