mirror of
https://github.com/LalleSX/4chan-XZ.git
synced 2026-01-30 09:48:12 +01:00
Bug fixes
This commit is contained in:
parent
04b144ff47
commit
f65fbc4fed
@ -1,8 +1,8 @@
|
|||||||
import Notice from '../classes/Notice.js'
|
import Notice from '../classes/Notice'
|
||||||
import { Conf } from '../globals/globals.js'
|
import { Conf } from '../globals/globals'
|
||||||
import $ from '../platform/$.js'
|
import $ from '../platform/$'
|
||||||
import CrossOrigin from '../platform/CrossOrigin.js'
|
import CrossOrigin from '../platform/CrossOrigin'
|
||||||
import { DAY, dict } from '../platform/helpers.js'
|
import { DAY, dict } from '../platform/helpers'
|
||||||
import archives from './archives.json'
|
import archives from './archives.json'
|
||||||
/*
|
/*
|
||||||
* decaffeinate suggestions:
|
* decaffeinate suggestions:
|
||||||
|
|||||||
@ -45,7 +45,7 @@ var ReportLink = {
|
|||||||
const { url, dims } = ReportLink
|
const { url, dims } = ReportLink
|
||||||
const id = Date.now()
|
const id = Date.now()
|
||||||
const set = `toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,${dims}`
|
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
|
export default ReportLink
|
||||||
|
|||||||
@ -22,7 +22,7 @@ var AntiAutoplay = {
|
|||||||
name: 'Disable Autoplaying Sounds',
|
name: 'Disable Autoplaying Sounds',
|
||||||
cb: this.node,
|
cb: this.node,
|
||||||
})
|
})
|
||||||
return $.ready(() => this.process(d.body))
|
return $.ready(() => this.process(doc))
|
||||||
},
|
},
|
||||||
|
|
||||||
stop(audio) {
|
stop(audio) {
|
||||||
|
|||||||
@ -90,7 +90,7 @@ var Banner = {
|
|||||||
Banner.original[this.className] = this.cloneNode(true)
|
Banner.original[this.className] = this.cloneNode(true)
|
||||||
}
|
}
|
||||||
this.contentEditable = true
|
this.contentEditable = true
|
||||||
for (var br of $$('br', this)) {
|
for (var br of $$('br', this.parentNode)) {
|
||||||
$.replace(br, $.tn('\n'))
|
$.replace(br, $.tn('\n'))
|
||||||
}
|
}
|
||||||
return this.focus()
|
return this.focus()
|
||||||
@ -104,7 +104,7 @@ var Banner = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
blur() {
|
blur() {
|
||||||
for (var br of $$('br', this)) {
|
for (var br of $$('br', this.parentNode)) {
|
||||||
$.replace(br, $.tn('\n'))
|
$.replace(br, $.tn('\n'))
|
||||||
}
|
}
|
||||||
if ((this.textContent = this.textContent.replace(/\n*$/, ''))) {
|
if ((this.textContent = this.textContent.replace(/\n*$/, ''))) {
|
||||||
|
|||||||
@ -51,10 +51,7 @@ var ExpandComment = {
|
|||||||
}
|
}
|
||||||
a.textContent = `Post No.${post} Loading...`
|
a.textContent = `Post No.${post} Loading...`
|
||||||
return $.cache(
|
return $.cache(
|
||||||
g.SITE.urls.threadJSON({
|
g.SITE.urls.threadJSON(post.thread.ID, post.thread.page),
|
||||||
boardID: post.boardID,
|
|
||||||
threadID: post.threadID,
|
|
||||||
}),
|
|
||||||
function () {
|
function () {
|
||||||
return ExpandComment.parse(this, a, post)
|
return ExpandComment.parse(this, a, post)
|
||||||
},
|
},
|
||||||
@ -83,7 +80,7 @@ var ExpandComment = {
|
|||||||
|
|
||||||
const { posts } = req.response
|
const { posts } = req.response
|
||||||
if ((spoilerRange = posts[0].custom_spoiler)) {
|
if ((spoilerRange = posts[0].custom_spoiler)) {
|
||||||
g.SITE.Build.spoilerRange[g.BOARD] = spoilerRange
|
g.SITE.Build.spoilerRange = spoilerRange
|
||||||
}
|
}
|
||||||
|
|
||||||
for (postObj of posts) {
|
for (postObj of posts) {
|
||||||
@ -102,13 +99,8 @@ var ExpandComment = {
|
|||||||
// Fix pathnames
|
// Fix pathnames
|
||||||
for (var quote of $$('.quotelink', clone)) {
|
for (var quote of $$('.quotelink', clone)) {
|
||||||
var href = quote.getAttribute('href')
|
var href = quote.getAttribute('href')
|
||||||
if (href[0] === '/') {
|
if (href && !href.match(/^https?:/)) {
|
||||||
continue
|
quote.setAttribute('href', g.SITE.urls.thread(post.thread.ID) + href)
|
||||||
} // 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}`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post.nodes.shortComment = comment
|
post.nodes.shortComment = comment
|
||||||
|
|||||||
@ -105,26 +105,25 @@ var ExpandThread = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
expand(thread, a) {
|
expand(thread, a) {
|
||||||
let status
|
const status = (ExpandThread.statuses[thread.ID] = {
|
||||||
ExpandThread.statuses[thread] = status = {}
|
numReplies: 0,
|
||||||
a.textContent = g.SITE.Build.summaryText(
|
req: null,
|
||||||
'...',
|
})
|
||||||
...Array.from(a.textContent.match(/\d+/g)),
|
const req = new XMLHttpRequest()
|
||||||
)
|
status.req = req
|
||||||
status.req = $.cache(
|
req.open('GET', thread.url, true)
|
||||||
g.SITE.urls.threadJSON({ boardID: thread.board.ID, threadID: thread.ID }),
|
req.responseType = 'document'
|
||||||
function () {
|
req.onload = function () {
|
||||||
if (this !== status.req) {
|
if (req.status === 200) {
|
||||||
return
|
return ExpandThread.expandCb(thread, a, req.response)
|
||||||
} // aborted
|
} else { // 404, 403, etc.
|
||||||
delete status.req
|
return ExpandThread.contract(thread, a, thread.nodes.root)
|
||||||
return ExpandThread.parse(this, thread, a)
|
}
|
||||||
},
|
}
|
||||||
)
|
req.onerror = function () {
|
||||||
return (status.numReplies = $$(
|
return ExpandThread.contract(thread, a, thread.nodes.root)
|
||||||
g.SITE.selectors.replyOriginal,
|
}
|
||||||
thread.nodes.root,
|
return req.send()
|
||||||
).length)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
contract(thread, a, threadRoot) {
|
contract(thread, a, threadRoot) {
|
||||||
@ -152,9 +151,8 @@ var ExpandThread = {
|
|||||||
for (var reply of replies) {
|
for (var reply of replies) {
|
||||||
// rm clones
|
// rm clones
|
||||||
if (Conf['Quote Inlining']) {
|
if (Conf['Quote Inlining']) {
|
||||||
var inlined
|
for (var quote of $$('.quote', reply)) {
|
||||||
while ((inlined = $('.inlined', reply))) {
|
$.rm(quote)
|
||||||
inlined.click()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
postsCount++
|
postsCount++
|
||||||
|
|||||||
@ -105,10 +105,7 @@ var FileInfo = {
|
|||||||
},
|
},
|
||||||
n() {
|
n() {
|
||||||
const fullname = this.file.name
|
const fullname = this.file.name
|
||||||
const shortname = SW.yotsuba.Build.shortFilename(
|
const shortname = this.file.url.match(/[^/]*$/)[0]
|
||||||
this.file.name,
|
|
||||||
this.isReply,
|
|
||||||
)
|
|
||||||
if (fullname === shortname) {
|
if (fullname === shortname) {
|
||||||
return { innerHTML: E(fullname), [isEscaped]: true }
|
return { innerHTML: E(fullname), [isEscaped]: true }
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -43,16 +43,28 @@ var IDColor = {
|
|||||||
compute(uid) {
|
compute(uid) {
|
||||||
// Convert chars to integers, bitshift and math to create a larger integer
|
// Convert chars to integers, bitshift and math to create a larger integer
|
||||||
// Create a nice string of binary
|
// 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.
|
// 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.
|
// Weight color luminance values, assign a font color that should be readable.
|
||||||
rgb.push($.luma(rgb) > 125 ? '#000' : '#fff')
|
const fontColor = $.luma ? ($.luma(rgb) > 125 ? '#000' : '#fff') : '#000';
|
||||||
|
|
||||||
// Cache.
|
// Cache color and font color.
|
||||||
return (this.ids[uid] = rgb)
|
const colorCode = `rgb(${rgb.join(',')})`;
|
||||||
|
this.ids[uid] = {
|
||||||
|
color: colorCode,
|
||||||
|
fontColor: fontColor
|
||||||
|
};
|
||||||
|
|
||||||
|
// Return only the color.
|
||||||
|
return colorCode;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
export default IDColor
|
export default IDColor
|
||||||
|
|||||||
@ -93,7 +93,7 @@ var Report = {
|
|||||||
return Report.archiveSubmit(urls, reason.value, (results) => {
|
return Report.archiveSubmit(urls, reason.value, (results) => {
|
||||||
this.action =
|
this.action =
|
||||||
'#archiveresults=' + encodeURIComponent(JSON.stringify(results))
|
'#archiveresults=' + encodeURIComponent(JSON.stringify(results))
|
||||||
return this.submit()
|
return submit.click()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -206,7 +206,7 @@ var ThreadUpdater = {
|
|||||||
case 404:
|
case 404:
|
||||||
// XXX workaround for 4chan sending false 404s
|
// XXX workaround for 4chan sending false 404s
|
||||||
return $.ajax(
|
return $.ajax(
|
||||||
g.SITE.urls.catalogJSON({ boardID: ThreadUpdater.thread.board.ID }),
|
g.SITE.urls.catalogJSON(ThreadUpdater.thread.board),
|
||||||
{
|
{
|
||||||
onloadend() {
|
onloadend() {
|
||||||
let confirmed
|
let confirmed
|
||||||
@ -345,10 +345,7 @@ var ThreadUpdater = {
|
|||||||
oldReq.abort()
|
oldReq.abort()
|
||||||
}
|
}
|
||||||
return (ThreadUpdater.req = $.whenModified(
|
return (ThreadUpdater.req = $.whenModified(
|
||||||
g.SITE.urls.threadJSON({
|
g.SITE.urls.threadJSON(ThreadUpdater.thread.fullID),
|
||||||
boardID: ThreadUpdater.thread.board.ID,
|
|
||||||
threadID: ThreadUpdater.thread.ID,
|
|
||||||
}),
|
|
||||||
'ThreadUpdater',
|
'ThreadUpdater',
|
||||||
ThreadUpdater.cb.load,
|
ThreadUpdater.cb.load,
|
||||||
{ timeout: MINUTE },
|
{ timeout: MINUTE },
|
||||||
@ -386,9 +383,8 @@ var ThreadUpdater = {
|
|||||||
// XXX Reject updates that falsely delete the last post.
|
// XXX Reject updates that falsely delete the last post.
|
||||||
if (
|
if (
|
||||||
postObjects[postObjects.length - 1].no < lastPost &&
|
postObjects[postObjects.length - 1].no < lastPost &&
|
||||||
new Date(req.getResponseHeader('Last-Modified')) -
|
postObjects.length > 1 &&
|
||||||
thread.posts.get(lastPost).info.date <
|
!OP.archived
|
||||||
30 * SECOND
|
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -287,7 +287,7 @@ var ThreadWatcher = {
|
|||||||
} else if (Conf['Auto Watch Reply']) {
|
} else if (Conf['Auto Watch Reply']) {
|
||||||
return ThreadWatcher.add(
|
return ThreadWatcher.add(
|
||||||
g.threads.get(boardID + '.' + threadID) ||
|
g.threads.get(boardID + '.' + threadID) ||
|
||||||
new Thread(threadID, g.boards[boardID] || new Board(boardID)),
|
new Thread(threadID + '', boardID),
|
||||||
cb,
|
cb,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -305,7 +305,9 @@ var ThreadWatcher = {
|
|||||||
!e.detail.threads.includes(`${boardID}.${threadID}`)
|
!e.detail.threads.includes(`${boardID}.${threadID}`)
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
!e.detail.threads.some((fullID) => +fullID.split('.')[1] > threadID)
|
!e.detail.threads.some((fullID) => {
|
||||||
|
return fullID.split('.')[1] === threadID
|
||||||
|
})
|
||||||
) {
|
) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,7 +145,7 @@ var Unread = {
|
|||||||
Unread.readCount = 0
|
Unread.readCount = 0
|
||||||
Unread.thread.posts.forEach((post) => Unread.addPost.call(post))
|
Unread.thread.posts.forEach((post) => Unread.addPost.call(post))
|
||||||
|
|
||||||
$.forceSync('Remember Last Read Post')
|
$.forceSync()
|
||||||
if (
|
if (
|
||||||
Conf['Remember Last Read Post'] &&
|
Conf['Remember Last Read Post'] &&
|
||||||
(!Unread.thread.isDead || Unread.thread.isArchived)
|
(!Unread.thread.isDead || Unread.thread.isArchived)
|
||||||
@ -306,7 +306,7 @@ var Unread = {
|
|||||||
|
|
||||||
saveLastReadPost: debounce(2 * SECOND, function () {
|
saveLastReadPost: debounce(2 * SECOND, function () {
|
||||||
let ID
|
let ID
|
||||||
$.forceSync('Remember Last Read Post')
|
$.forceSync()
|
||||||
if (!Conf['Remember Last Read Post'] || !Unread.db) {
|
if (!Conf['Remember Last Read Post'] || !Unread.db) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -391,7 +391,7 @@ var Unread = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
saveThreadWatcherCount: debounce(2 * SECOND, function () {
|
saveThreadWatcherCount: debounce(2 * SECOND, function () {
|
||||||
$.forceSync('Remember Last Read Post')
|
$.forceSync()
|
||||||
if (
|
if (
|
||||||
Conf['Remember Last Read Post'] &&
|
Conf['Remember Last Read Post'] &&
|
||||||
(!Unread.thread.isDead || Unread.thread.isArchived)
|
(!Unread.thread.isDead || Unread.thread.isArchived)
|
||||||
|
|||||||
@ -171,17 +171,13 @@ var UnreadIndex = {
|
|||||||
const thread = Get.threadFromNode(this)
|
const thread = Get.threadFromNode(this)
|
||||||
UnreadIndex.lastReadPost[thread.fullID] = thread.lastPost
|
UnreadIndex.lastReadPost[thread.fullID] = thread.lastPost
|
||||||
UnreadIndex.db.set({
|
UnreadIndex.db.set({
|
||||||
boardID: thread.board.ID,
|
boardID: g.BOARD.ID,
|
||||||
threadID: thread.ID,
|
threadID: thread.ID,
|
||||||
val: thread.lastPost,
|
val: thread.lastPost,
|
||||||
})
|
})
|
||||||
$.rm(UnreadIndex.hr[thread.fullID])
|
$.rm(UnreadIndex.hr[thread.fullID])
|
||||||
thread.nodes.root.classList.remove('unread-thread')
|
thread.nodes.root.classList.remove('unread-thread')
|
||||||
return ThreadWatcher.update(g.SITE.ID, thread.board.ID, thread.ID, {
|
return ThreadWatcher.update(thread)
|
||||||
last: thread.lastPost,
|
|
||||||
unread: 0,
|
|
||||||
quotingYou: 0,
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
export default UnreadIndex
|
export default UnreadIndex
|
||||||
|
|||||||
@ -128,7 +128,7 @@ var QuoteInline = {
|
|||||||
// Will only unhide if there's no inlined backlinks of it anymore.
|
// Will only unhide if there's no inlined backlinks of it anymore.
|
||||||
if (isBacklink && Conf['Forward Hiding']) {
|
if (isBacklink && Conf['Forward Hiding']) {
|
||||||
$.addClass(post.nodes.root, 'forwarded')
|
$.addClass(post.nodes.root, 'forwarded')
|
||||||
post.forwarded++ || (post.forwarded = 1)
|
post.forwarded = (post.forwarded || 0) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrease the unread count if this post
|
// Decrease the unread count if this post
|
||||||
@ -152,7 +152,7 @@ var QuoteInline = {
|
|||||||
const qroot = $.x('ancestor::*[contains(@class,"postContainer")][1]', root)
|
const qroot = $.x('ancestor::*[contains(@class,"postContainer")][1]', root)
|
||||||
const { parentNode } = root
|
const { parentNode } = root
|
||||||
$.rm(root)
|
$.rm(root)
|
||||||
$.event('PostsRemoved', null, parentNode)
|
$.event('remove', root)
|
||||||
|
|
||||||
if (!$('.inline', qroot)) {
|
if (!$('.inline', qroot)) {
|
||||||
$.rmClass(qroot, 'hasInline')
|
$.rmClass(qroot, 'hasInline')
|
||||||
|
|||||||
@ -75,6 +75,7 @@ var QuotePreview = {
|
|||||||
latestEvent: e,
|
latestEvent: e,
|
||||||
endEvents: 'mouseout click',
|
endEvents: 'mouseout click',
|
||||||
cb: QuotePreview.mouseout,
|
cb: QuotePreview.mouseout,
|
||||||
|
cbArgs: [this, qp],
|
||||||
})
|
})
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -1,11 +1,5 @@
|
|||||||
import Main from '../main/Main'
|
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 {
|
export default class Callbacks {
|
||||||
static initClass() {
|
static initClass() {
|
||||||
this.Post = new Callbacks('Post')
|
this.Post = new Callbacks('Post')
|
||||||
|
|||||||
@ -9,15 +9,12 @@ export default class CatalogThreadNative {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor(root) {
|
constructor(root) {
|
||||||
this.nodes = {
|
const thumb = $(g.SITE.selectors.catalog.thumb, root);
|
||||||
root,
|
this.nodes = { root, thumb };
|
||||||
thumb: $(g.SITE.selectors.catalog.thumb, root),
|
this.siteID = g.SITE.ID;
|
||||||
}
|
this.boardID = thumb.parentNode.pathname.split(/\/+/)[1];
|
||||||
this.siteID = g.SITE.ID
|
this.board = g.boards[this.boardID] ?? new Board(this.boardID);
|
||||||
this.boardID = this.nodes.thumb.parentNode.pathname.split(/\/+/)[1]
|
this.ID = this.threadID = +root.dataset.id || $(root).data('id');
|
||||||
this.board = g.boards[this.boardID] || new Board(this.boardID)
|
this.thread = this.board.threads.get(this.ID) ?? new Thread(this.ID, this.board);
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,6 +54,7 @@ export default class Post {
|
|||||||
return el
|
return el
|
||||||
})()
|
})()
|
||||||
normalizedOriginal: any
|
normalizedOriginal: any
|
||||||
|
static get: any
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return this.ID
|
return this.ID
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
import $ from '../platform/$'
|
import $ from '../platform/$'
|
||||||
class ShimSet {
|
class ShimSet {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.elements = $.dict()
|
this.elements = $.cache()
|
||||||
this.size = 0
|
this.size = 0
|
||||||
}
|
}
|
||||||
has(value) {
|
has(value) {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import { debounce, dict, MINUTE, platform, SECOND } from "./helpers";
|
|||||||
const $ = (selector, root = document.body) => root.querySelector(selector);
|
const $ = (selector, root = document.body) => root.querySelector(selector);
|
||||||
|
|
||||||
$.id = id => d.getElementById(id);
|
$.id = id => d.getElementById(id);
|
||||||
|
$.cache = dict();
|
||||||
$.ready = function (fc) {
|
$.ready = function (fc) {
|
||||||
if (d.readyState !== 'loading') {
|
if (d.readyState !== 'loading') {
|
||||||
$.queueTask(fc);
|
$.queueTask(fc);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user