diff --git a/src/Archive/Redirect.js b/src/Archive/Redirect.js index 12a88b1..648a148 100644 --- a/src/Archive/Redirect.js +++ b/src/Archive/Redirect.js @@ -1,8 +1,8 @@ -import Notice from '../classes/Notice.js' -import { Conf } from '../globals/globals.js' -import $ from '../platform/$.js' -import CrossOrigin from '../platform/CrossOrigin.js' -import { DAY, dict } from '../platform/helpers.js' +import Notice from '../classes/Notice' +import { Conf } from '../globals/globals' +import $ from '../platform/$' +import CrossOrigin from '../platform/CrossOrigin' +import { DAY, dict } from '../platform/helpers' import archives from './archives.json' /* * decaffeinate suggestions: diff --git a/src/Menu/ReportLink.js b/src/Menu/ReportLink.js index 3969948..fd39752 100644 --- a/src/Menu/ReportLink.js +++ b/src/Menu/ReportLink.js @@ -45,7 +45,7 @@ var ReportLink = { const { url, dims } = ReportLink const id = Date.now() const set = `toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,${dims}` - return window.open(url, id, set) + return window.open(url, `report${id}`, set) }, } export default ReportLink diff --git a/src/Miscellaneous/AntiAutoplay.js b/src/Miscellaneous/AntiAutoplay.js index cbac766..9ecca0a 100644 --- a/src/Miscellaneous/AntiAutoplay.js +++ b/src/Miscellaneous/AntiAutoplay.js @@ -22,7 +22,7 @@ var AntiAutoplay = { name: 'Disable Autoplaying Sounds', cb: this.node, }) - return $.ready(() => this.process(d.body)) + return $.ready(() => this.process(doc)) }, stop(audio) { diff --git a/src/Miscellaneous/Banner.js b/src/Miscellaneous/Banner.js index c27f51e..264842f 100644 --- a/src/Miscellaneous/Banner.js +++ b/src/Miscellaneous/Banner.js @@ -90,7 +90,7 @@ var Banner = { Banner.original[this.className] = this.cloneNode(true) } this.contentEditable = true - for (var br of $$('br', this)) { + for (var br of $$('br', this.parentNode)) { $.replace(br, $.tn('\n')) } return this.focus() @@ -104,7 +104,7 @@ var Banner = { }, blur() { - for (var br of $$('br', this)) { + for (var br of $$('br', this.parentNode)) { $.replace(br, $.tn('\n')) } if ((this.textContent = this.textContent.replace(/\n*$/, ''))) { diff --git a/src/Miscellaneous/ExpandComment.js b/src/Miscellaneous/ExpandComment.js index 8d6be4e..ddc40bc 100644 --- a/src/Miscellaneous/ExpandComment.js +++ b/src/Miscellaneous/ExpandComment.js @@ -51,10 +51,7 @@ var ExpandComment = { } a.textContent = `Post No.${post} Loading...` return $.cache( - g.SITE.urls.threadJSON({ - boardID: post.boardID, - threadID: post.threadID, - }), + g.SITE.urls.threadJSON(post.thread.ID, post.thread.page), function () { return ExpandComment.parse(this, a, post) }, @@ -83,7 +80,7 @@ var ExpandComment = { const { posts } = req.response if ((spoilerRange = posts[0].custom_spoiler)) { - g.SITE.Build.spoilerRange[g.BOARD] = spoilerRange + g.SITE.Build.spoilerRange = spoilerRange } for (postObj of posts) { @@ -102,13 +99,8 @@ var ExpandComment = { // Fix pathnames for (var quote of $$('.quotelink', clone)) { var href = quote.getAttribute('href') - if (href[0] === '/') { - continue - } // Cross-board quote, or board link - if (href[0] === '#') { - quote.href = `${a.pathname.split(/\/+/).splice(0, 4).join('/')}${href}` - } else { - quote.href = `${a.pathname.split(/\/+/).splice(0, 3).join('/')}/${href}` + if (href && !href.match(/^https?:/)) { + quote.setAttribute('href', g.SITE.urls.thread(post.thread.ID) + href) } } post.nodes.shortComment = comment diff --git a/src/Miscellaneous/ExpandThread.js b/src/Miscellaneous/ExpandThread.js index a1507b0..5ea90af 100644 --- a/src/Miscellaneous/ExpandThread.js +++ b/src/Miscellaneous/ExpandThread.js @@ -105,26 +105,25 @@ var ExpandThread = { }, expand(thread, a) { - let status - ExpandThread.statuses[thread] = status = {} - a.textContent = g.SITE.Build.summaryText( - '...', - ...Array.from(a.textContent.match(/\d+/g)), - ) - status.req = $.cache( - g.SITE.urls.threadJSON({ boardID: thread.board.ID, threadID: thread.ID }), - function () { - if (this !== status.req) { - return - } // aborted - delete status.req - return ExpandThread.parse(this, thread, a) - }, - ) - return (status.numReplies = $$( - g.SITE.selectors.replyOriginal, - thread.nodes.root, - ).length) + const status = (ExpandThread.statuses[thread.ID] = { + numReplies: 0, + req: null, + }) + const req = new XMLHttpRequest() + status.req = req + req.open('GET', thread.url, true) + req.responseType = 'document' + req.onload = function () { + if (req.status === 200) { + return ExpandThread.expandCb(thread, a, req.response) + } else { // 404, 403, etc. + return ExpandThread.contract(thread, a, thread.nodes.root) + } + } + req.onerror = function () { + return ExpandThread.contract(thread, a, thread.nodes.root) + } + return req.send() }, contract(thread, a, threadRoot) { @@ -152,9 +151,8 @@ var ExpandThread = { for (var reply of replies) { // rm clones if (Conf['Quote Inlining']) { - var inlined - while ((inlined = $('.inlined', reply))) { - inlined.click() + for (var quote of $$('.quote', reply)) { + $.rm(quote) } } postsCount++ diff --git a/src/Miscellaneous/FileInfo.tsx b/src/Miscellaneous/FileInfo.tsx index ed2cbfc..950fccc 100644 --- a/src/Miscellaneous/FileInfo.tsx +++ b/src/Miscellaneous/FileInfo.tsx @@ -105,10 +105,7 @@ var FileInfo = { }, n() { const fullname = this.file.name - const shortname = SW.yotsuba.Build.shortFilename( - this.file.name, - this.isReply, - ) + const shortname = this.file.url.match(/[^/]*$/)[0] if (fullname === shortname) { return { innerHTML: E(fullname), [isEscaped]: true } } else { diff --git a/src/Miscellaneous/IDColor.js b/src/Miscellaneous/IDColor.js index 118a9ad..76e21d1 100644 --- a/src/Miscellaneous/IDColor.js +++ b/src/Miscellaneous/IDColor.js @@ -43,16 +43,28 @@ var IDColor = { compute(uid) { // Convert chars to integers, bitshift and math to create a larger integer // Create a nice string of binary - const hash = g.SITE.uidColor ? g.SITE.uidColor(uid) : parseInt(uid, 16) - + let hash; + if (typeof g !== 'undefined' && g.SITE && g.SITE.uidColor) { + hash = g.SITE.uidColor(uid); + } else { + hash = parseInt(uid, 16); + } + // Convert binary string to numerical values with bitshift and '&' truncation. - const rgb = [(hash >> 16) & 0xff, (hash >> 8) & 0xff, hash & 0xff] - + const rgb = [(hash >> 16) & 0xff, (hash >> 8) & 0xff, hash & 0xff]; + // Weight color luminance values, assign a font color that should be readable. - rgb.push($.luma(rgb) > 125 ? '#000' : '#fff') - - // Cache. - return (this.ids[uid] = rgb) + const fontColor = $.luma ? ($.luma(rgb) > 125 ? '#000' : '#fff') : '#000'; + + // Cache color and font color. + const colorCode = `rgb(${rgb.join(',')})`; + this.ids[uid] = { + color: colorCode, + fontColor: fontColor + }; + + // Return only the color. + return colorCode; }, } export default IDColor diff --git a/src/Miscellaneous/Report.js b/src/Miscellaneous/Report.js index 182d132..7ab9495 100644 --- a/src/Miscellaneous/Report.js +++ b/src/Miscellaneous/Report.js @@ -93,7 +93,7 @@ var Report = { return Report.archiveSubmit(urls, reason.value, (results) => { this.action = '#archiveresults=' + encodeURIComponent(JSON.stringify(results)) - return this.submit() + return submit.click() }) } }) diff --git a/src/Monitoring/ThreadUpdater.js b/src/Monitoring/ThreadUpdater.js index ab4d190..29bb994 100644 --- a/src/Monitoring/ThreadUpdater.js +++ b/src/Monitoring/ThreadUpdater.js @@ -206,7 +206,7 @@ var ThreadUpdater = { case 404: // XXX workaround for 4chan sending false 404s return $.ajax( - g.SITE.urls.catalogJSON({ boardID: ThreadUpdater.thread.board.ID }), + g.SITE.urls.catalogJSON(ThreadUpdater.thread.board), { onloadend() { let confirmed @@ -345,10 +345,7 @@ var ThreadUpdater = { oldReq.abort() } return (ThreadUpdater.req = $.whenModified( - g.SITE.urls.threadJSON({ - boardID: ThreadUpdater.thread.board.ID, - threadID: ThreadUpdater.thread.ID, - }), + g.SITE.urls.threadJSON(ThreadUpdater.thread.fullID), 'ThreadUpdater', ThreadUpdater.cb.load, { timeout: MINUTE }, @@ -386,9 +383,8 @@ var ThreadUpdater = { // XXX Reject updates that falsely delete the last post. if ( postObjects[postObjects.length - 1].no < lastPost && - new Date(req.getResponseHeader('Last-Modified')) - - thread.posts.get(lastPost).info.date < - 30 * SECOND + postObjects.length > 1 && + !OP.archived ) { return } diff --git a/src/Monitoring/ThreadWatcher.js b/src/Monitoring/ThreadWatcher.js index 6c01265..9237127 100644 --- a/src/Monitoring/ThreadWatcher.js +++ b/src/Monitoring/ThreadWatcher.js @@ -287,7 +287,7 @@ var ThreadWatcher = { } else if (Conf['Auto Watch Reply']) { return ThreadWatcher.add( g.threads.get(boardID + '.' + threadID) || - new Thread(threadID, g.boards[boardID] || new Board(boardID)), + new Thread(threadID + '', boardID), cb, ) } @@ -305,7 +305,9 @@ var ThreadWatcher = { !e.detail.threads.includes(`${boardID}.${threadID}`) ) { if ( - !e.detail.threads.some((fullID) => +fullID.split('.')[1] > threadID) + !e.detail.threads.some((fullID) => { + return fullID.split('.')[1] === threadID + }) ) { continue } diff --git a/src/Monitoring/Unread.js b/src/Monitoring/Unread.js index ff94ade..3344a7c 100644 --- a/src/Monitoring/Unread.js +++ b/src/Monitoring/Unread.js @@ -145,7 +145,7 @@ var Unread = { Unread.readCount = 0 Unread.thread.posts.forEach((post) => Unread.addPost.call(post)) - $.forceSync('Remember Last Read Post') + $.forceSync() if ( Conf['Remember Last Read Post'] && (!Unread.thread.isDead || Unread.thread.isArchived) @@ -306,7 +306,7 @@ var Unread = { saveLastReadPost: debounce(2 * SECOND, function () { let ID - $.forceSync('Remember Last Read Post') + $.forceSync() if (!Conf['Remember Last Read Post'] || !Unread.db) { return } @@ -391,7 +391,7 @@ var Unread = { }, saveThreadWatcherCount: debounce(2 * SECOND, function () { - $.forceSync('Remember Last Read Post') + $.forceSync() if ( Conf['Remember Last Read Post'] && (!Unread.thread.isDead || Unread.thread.isArchived) diff --git a/src/Monitoring/UnreadIndex.js b/src/Monitoring/UnreadIndex.js index b712016..017e775 100644 --- a/src/Monitoring/UnreadIndex.js +++ b/src/Monitoring/UnreadIndex.js @@ -171,17 +171,13 @@ var UnreadIndex = { const thread = Get.threadFromNode(this) UnreadIndex.lastReadPost[thread.fullID] = thread.lastPost UnreadIndex.db.set({ - boardID: thread.board.ID, + boardID: g.BOARD.ID, threadID: thread.ID, val: thread.lastPost, }) $.rm(UnreadIndex.hr[thread.fullID]) thread.nodes.root.classList.remove('unread-thread') - return ThreadWatcher.update(g.SITE.ID, thread.board.ID, thread.ID, { - last: thread.lastPost, - unread: 0, - quotingYou: 0, - }) + return ThreadWatcher.update(thread) }, } export default UnreadIndex diff --git a/src/Quotelinks/QuoteInline.js b/src/Quotelinks/QuoteInline.js index 342f636..3e1e4e9 100644 --- a/src/Quotelinks/QuoteInline.js +++ b/src/Quotelinks/QuoteInline.js @@ -128,7 +128,7 @@ var QuoteInline = { // Will only unhide if there's no inlined backlinks of it anymore. if (isBacklink && Conf['Forward Hiding']) { $.addClass(post.nodes.root, 'forwarded') - post.forwarded++ || (post.forwarded = 1) + post.forwarded = (post.forwarded || 0) + 1 } // Decrease the unread count if this post @@ -152,7 +152,7 @@ var QuoteInline = { const qroot = $.x('ancestor::*[contains(@class,"postContainer")][1]', root) const { parentNode } = root $.rm(root) - $.event('PostsRemoved', null, parentNode) + $.event('remove', root) if (!$('.inline', qroot)) { $.rmClass(qroot, 'hasInline') diff --git a/src/Quotelinks/QuotePreview.js b/src/Quotelinks/QuotePreview.js index 344ffbe..fe74294 100644 --- a/src/Quotelinks/QuotePreview.js +++ b/src/Quotelinks/QuotePreview.js @@ -75,6 +75,7 @@ var QuotePreview = { latestEvent: e, endEvents: 'mouseout click', cb: QuotePreview.mouseout, + cbArgs: [this, qp], }) if ( diff --git a/src/classes/Callbacks.js b/src/classes/Callbacks.js index c35106b..9aa4463 100644 --- a/src/classes/Callbacks.js +++ b/src/classes/Callbacks.js @@ -1,11 +1,5 @@ import Main from '../main/Main' -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * DS206: Consider reworking classes to avoid initClass - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md - */ export default class Callbacks { static initClass() { this.Post = new Callbacks('Post') diff --git a/src/classes/CatalogThreadNative.js b/src/classes/CatalogThreadNative.js index 8cfc701..38de62a 100644 --- a/src/classes/CatalogThreadNative.js +++ b/src/classes/CatalogThreadNative.js @@ -9,15 +9,12 @@ export default class CatalogThreadNative { } constructor(root) { - this.nodes = { - root, - thumb: $(g.SITE.selectors.catalog.thumb, root), - } - this.siteID = g.SITE.ID - this.boardID = this.nodes.thumb.parentNode.pathname.split(/\/+/)[1] - this.board = g.boards[this.boardID] || new Board(this.boardID) - this.ID = this.threadID = +(root.dataset.id || root.id).match(/\d*$/)[0] - this.thread = - this.board.threads.get(this.ID) || new Thread(this.ID, this.board) + const thumb = $(g.SITE.selectors.catalog.thumb, root); + this.nodes = { root, thumb }; + this.siteID = g.SITE.ID; + this.boardID = thumb.parentNode.pathname.split(/\/+/)[1]; + this.board = g.boards[this.boardID] ?? new Board(this.boardID); + this.ID = this.threadID = +root.dataset.id || $(root).data('id'); + this.thread = this.board.threads.get(this.ID) ?? new Thread(this.ID, this.board); } } diff --git a/src/classes/Post.ts b/src/classes/Post.ts index d86a008..aae3b37 100644 --- a/src/classes/Post.ts +++ b/src/classes/Post.ts @@ -54,6 +54,7 @@ export default class Post { return el })() normalizedOriginal: any + static get: any toString() { return this.ID diff --git a/src/classes/ShimSet.js b/src/classes/ShimSet.js index 0ddff27..e011569 100644 --- a/src/classes/ShimSet.js +++ b/src/classes/ShimSet.js @@ -6,7 +6,7 @@ import $ from '../platform/$' class ShimSet { constructor() { - this.elements = $.dict() + this.elements = $.cache() this.size = 0 } has(value) { diff --git a/src/platform/$.js b/src/platform/$.js index 48e5d2b..3a926a1 100644 --- a/src/platform/$.js +++ b/src/platform/$.js @@ -17,7 +17,7 @@ import { debounce, dict, MINUTE, platform, SECOND } from "./helpers"; const $ = (selector, root = document.body) => root.querySelector(selector); $.id = id => d.getElementById(id); - +$.cache = dict(); $.ready = function (fc) { if (d.readyState !== 'loading') { $.queueTask(fc);