Bug fixes

This commit is contained in:
Lalle 2023-04-18 20:01:29 +02:00
parent 04b144ff47
commit f65fbc4fed
No known key found for this signature in database
GPG Key ID: A6583D207A8F6B0D
20 changed files with 82 additions and 96 deletions

View File

@ -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:

View File

@ -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

View File

@ -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) {

View File

@ -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*$/, ''))) {

View File

@ -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

View File

@ -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++

View File

@ -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 {

View File

@ -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

View File

@ -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()
})
}
})

View File

@ -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
}

View File

@ -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
}

View File

@ -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)

View File

@ -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

View File

@ -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')

View File

@ -75,6 +75,7 @@ var QuotePreview = {
latestEvent: e,
endEvents: 'mouseout click',
cb: QuotePreview.mouseout,
cbArgs: [this, qp],
})
if (

View File

@ -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')

View File

@ -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);
}
}

View File

@ -54,6 +54,7 @@ export default class Post {
return el
})()
normalizedOriginal: any
static get: any
toString() {
return this.ID

View File

@ -6,7 +6,7 @@
import $ from '../platform/$'
class ShimSet {
constructor() {
this.elements = $.dict()
this.elements = $.cache()
this.size = 0
}
has(value) {

View File

@ -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);