This commit is contained in:
Lalle 2023-04-27 22:21:31 +02:00
parent 00afadd988
commit f0fe377bc2
No known key found for this signature in database
GPG Key ID: A6583D207A8F6B0D
28 changed files with 66 additions and 88 deletions

View File

@ -87,7 +87,7 @@ const Filter = {
} }
// Don't mix up filter flags with the regular expression. // Don't mix up filter flags with the regular expression.
var filter = line.replace(regexp[0], '') const filter = line.replace(regexp[0], '')
// List of the boards this filter applies to. // List of the boards this filter applies to.
const boards = this.parseBoards( const boards = this.parseBoards(

View File

@ -127,7 +127,7 @@ var Index = {
const watchSettings = function (e) { const watchSettings = function (e) {
if ((input = $.getOwn(inputs, e.target.name))) { if ((input = $.getOwn(inputs, e.target.name))) {
input.checked = e.target.checked input.checked = e.target.checked
return $.event('change', null, input) return $.event('change')
} }
} }
$.on(d, 'OpenSettings', () => $.on(d, 'OpenSettings', () =>
@ -249,7 +249,7 @@ var Index = {
const board = $('.board') const board = $('.board')
$.replace(board, Index.root) $.replace(board, Index.root)
if (Index.loaded) { if (Index.loaded) {
$.event('PostsInserted', null, Index.root) $.event('PostsInserted')
} }
// Hacks: // Hacks:
// - When removing an element from the document during page load, // - When removing an element from the document during page load,
@ -413,7 +413,7 @@ var Index = {
} }
} }
types[(i + 1) % types.length].selected = true types[(i + 1) % types.length].selected = true
return $.event('change', null, Index.selectSort) return $.event('change')
}, },
cb: { cb: {
@ -1082,9 +1082,7 @@ var Index = {
return thread.collect() return thread.collect()
} }
}) })
$.event('IndexUpdate', { $.event('IndexUpdate')
threads: Index.liveThreadIDs.map(ID => `${g.BOARD}.${ID}`),
})
}, },
isHidden(threadID) { isHidden(threadID) {
@ -1193,11 +1191,7 @@ var Index = {
Main.callbackNodes('Thread', newThreads) Main.callbackNodes('Thread', newThreads)
Main.callbackNodes('Post', newPosts) Main.callbackNodes('Post', newPosts)
Index.updateHideLabel() Index.updateHideLabel()
$.event('IndexRefreshInternal', { $.event('IndexRefreshInternal')
threadIDs: threads.map(t => t.fullID),
isCatalog,
})
return threads return threads
}, },
@ -1424,7 +1418,7 @@ var Index = {
$.rmAll(Index.root) $.rmAll(Index.root)
$.rmAll(Header.hover) $.rmAll(Header.hover)
if (Index.loaded && Index.root.parentNode) { if (Index.loaded && Index.root.parentNode) {
$.event('PostsRemoved', null, Index.root) $.event('PostsRemoved')
} }
if (Conf['Index Mode'] === 'catalog') { if (Conf['Index Mode'] === 'catalog') {
Index.buildCatalog(threadIDs) Index.buildCatalog(threadIDs)
@ -1447,7 +1441,7 @@ var Index = {
} }
$.add(Index.root, nodes) $.add(Index.root, nodes)
if (Index.root.parentNode) { if (Index.root.parentNode) {
$.event('PostsInserted', null, Index.root) $.event('PostsInserted')
} }
Index.loaded = true Index.loaded = true
}, },
@ -1467,7 +1461,7 @@ var Index = {
return $.queueTask(fn) return $.queueTask(fn)
} else { } else {
if (Index.root.parentNode) { if (Index.root.parentNode) {
$.event('PostsInserted', null, Index.root) $.event('PostsInserted')
} }
return (Index.loaded = true) return (Index.loaded = true)
} }

View File

@ -713,7 +713,7 @@ Enable it on boards.${
if (compareString < '00001.00011.00019.00003' && !Settings.dialog) { if (compareString < '00001.00011.00019.00003' && !Settings.dialog) {
$.queueTask(() => $.queueTask(() =>
Settings.warnings.ads( Settings.warnings.ads(
item => new Notice('warning', [...Array.from(item.childNodes)]) item => new Notice('warn',`4chan X: ${item} has been removed.`)
) )
) )
} }
@ -1328,7 +1328,7 @@ vp-replace
for (boardID in Conf['selectedArchives']) { for (boardID in Conf['selectedArchives']) {
const data = Conf['selectedArchives'][boardID] const data = Conf['selectedArchives'][boardID]
for (const type in data) { for (const type in data) {
var select let select
const id = data[type] const id = data[type]
if ( if (
(select = $( (select = $(

View File

@ -52,7 +52,7 @@ const FappeTyme = {
this.parentNode.id.replace('shortcut-', '') this.parentNode.id.replace('shortcut-', '')
) )
check.checked = !check.checked check.checked = !check.checked
return $.event('change', null, check) return $.event('change')
}) })
Header.addShortcut(lc, indicator, 410) Header.addShortcut(lc, indicator, 410)
} }

View File

@ -649,7 +649,7 @@ const Gallery = {
if (['Hide Thumbnails', 'Fit Width', 'Fit Height'].includes(name)) { if (['Hide Thumbnails', 'Fit Width', 'Fit Height'].includes(name)) {
$.on(input, 'change', Gallery.cb.setFitness) $.on(input, 'change', Gallery.cb.setFitness)
} }
$.event('change', null, input) $.event('change')
$.on(input, 'change', $.cb.checked) $.on(input, 'change', $.cb.checked)
if ( if (
[ [

View File

@ -516,7 +516,7 @@ const ImageExpand = {
if (['Fit width', 'Fit height'].includes(name)) { if (['Fit width', 'Fit height'].includes(name)) {
$.on(input, 'change', ImageExpand.cb.setFitness) $.on(input, 'change', ImageExpand.cb.setFitness)
} }
$.event('change', null, input) $.event('change')
$.on(input, 'change', $.cb.checked) $.on(input, 'change', $.cb.checked)
return { el: label } return { el: label }
}, },

View File

@ -55,7 +55,6 @@ const ImageHover = {
mouseover(post, file) { mouseover(post, file) {
return function (e) { return function (e) {
let el, height, width let el, height, width
// @ts-ignore
if (!doc.contains(this)) { if (!doc.contains(this)) {
return return
} }
@ -92,7 +91,6 @@ const ImageHover = {
Volume.setup(el) Volume.setup(el)
if (Conf['Autoplay']) { if (Conf['Autoplay']) {
el.play() el.play()
// @ts-ignore
if (this.nodeName === 'VIDEO') { if (this.nodeName === 'VIDEO') {
this.currentTime = el.currentTime this.currentTime = el.currentTime
} }
@ -144,7 +142,7 @@ const ImageHover = {
this.src = file this.src = file
return return
} }
return $.rm(this) return $.rm(this.src)
}) })
} }
}, },

View File

@ -17,7 +17,7 @@ import Site from '../site/Site'
* 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 CatalogLinks = { const CatalogLinks = {
init() { init() {
if ( if (
g.SITE.software === 'yotsuba' && g.SITE.software === 'yotsuba' &&

View File

@ -9,7 +9,7 @@ import $$ from '../platform/$$'
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* 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 ExpandComment = { const ExpandComment = {
init() { init() {
if ( if (
g.VIEW !== 'index' || g.VIEW !== 'index' ||

View File

@ -164,7 +164,7 @@ var ExpandThread = {
} }
if (Index.enabled) { if (Index.enabled) {
// otherwise handled by Main.addPosts // otherwise handled by Main.addPosts
$.event('PostsRemoved', null, a.parentNode) $.event('PostsRemoved')
} }
a.textContent = g.SITE.Build.summaryText('+', postsCount, filesCount) a.textContent = g.SITE.Build.summaryText('+', postsCount, filesCount)
return $.rm($('.summary-bottom', threadRoot)) return $.rm($('.summary-bottom', threadRoot))
@ -208,7 +208,7 @@ var ExpandThread = {
} }
Main.callbackNodes('Post', posts) Main.callbackNodes('Post', posts)
$.after(a, postsRoot) $.after(a, postsRoot)
$.event('PostsInserted', null, a.parentNode) $.event('PostsInserted')
const postsCount = postsRoot.length const postsCount = postsRoot.length
a.textContent = g.SITE.Build.summaryText('-', postsCount, filesCount) a.textContent = g.SITE.Build.summaryText('-', postsCount, filesCount)

View File

@ -12,7 +12,7 @@ import SW from '../site/SW'
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* 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 FileInfo = { const FileInfo = {
init() { init() {
if ( if (
!['index', 'thread', 'archive'].includes(g.VIEW) || !['index', 'thread', 'archive'].includes(g.VIEW) ||

View File

@ -164,7 +164,7 @@ var Fourchan = {
return return
} }
$.off(d, 'PostsInserted', cb) $.off(d, 'PostsInserted', cb)
return $.event('mathjax', null, this.nodes.comment) return $.event('mathjax')
} }
$.on(d, 'PostsInserted', cb) $.on(d, 'PostsInserted', cb)
return cb() return cb()

View File

@ -567,7 +567,7 @@ var Keybinds = {
ta.setSelectionRange(range, range) ta.setSelectionRange(range, range)
// Fire the 'input' event // Fire the 'input' event
return $.event('input', null, ta) return $.event('input')
}, },
sage() { sage() {

View File

@ -20,7 +20,7 @@ const ReplyPruning = {
this.summary.style.cursor = 'pointer' this.summary.style.cursor = 'pointer'
$.on(this.summary, 'click', () => { $.on(this.summary, 'click', () => {
this.inputs.enabled.checked = !this.inputs.enabled.checked this.inputs.enabled.checked = !this.inputs.enabled.checked
return $.event('change', null, this.inputs.enabled) return $.event('change')
}) })
const label = UI.checkbox( const label = UI.checkbox(
@ -70,7 +70,7 @@ const ReplyPruning = {
const other = QuoteThreading.input const other = QuoteThreading.input
if (this.checked && other?.checked) { if (this.checked && other?.checked) {
other.checked = false other.checked = false
$.event('change', null, other) $.event('change')
} }
return (ReplyPruning.active = this.checked) return (ReplyPruning.active = this.checked)
}, },
@ -78,7 +78,7 @@ const ReplyPruning = {
showIfHidden(id) { showIfHidden(id) {
if (ReplyPruning.container && $(`#${id}`, ReplyPruning.container)) { if (ReplyPruning.container && $(`#${id}`, ReplyPruning.container)) {
ReplyPruning.inputs.enabled.checked = false ReplyPruning.inputs.enabled.checked = false
return $.event('change', null, ReplyPruning.inputs.enabled) return $.event('change')
} }
}, },
@ -186,7 +186,7 @@ const ReplyPruning = {
} }
} }
$.after(ReplyPruning.summary, frag) $.after(ReplyPruning.summary, frag)
$.event('PostsInserted', null, ReplyPruning.summary.parentNode) $.event('PostsInserted')
} }
ReplyPruning.summary.textContent = ReplyPruning.active ReplyPruning.summary.textContent = ReplyPruning.active

View File

@ -2,7 +2,6 @@ import BoardConfig from '../General/BoardConfig'
import { d, g } from '../globals/globals' import { d, g } from '../globals/globals'
import Post from './Post' import Post from './Post'
import SimpleDict from './SimpleDict' import SimpleDict from './SimpleDict'
import Site from './Site'
import Thread from './Thread' import Thread from './Thread'
/* /*
@ -13,7 +12,7 @@ import Thread from './Thread'
export default class Board { export default class Board {
ID: string ID: string
boardID: string boardID: string
siteID: string | Site siteID: string
threads: SimpleDict<Thread> threads: SimpleDict<Thread>
posts: SimpleDict<Post> posts: SimpleDict<Post>
config: config:

View File

@ -25,38 +25,30 @@ class Callbacks {
this[name as keyof Callbacks] = cb this[name as keyof Callbacks] = cb
} }
execute(node: any, keys: string[] = this.keys, force = false): void { execute(node: Node, keys: (keyof Callbacks)[] = this.keys, force = false): void {
let errors: any[]
if (node.callbacksExecuted && !force) { if (node.callbacksExecuted && !force) {
return return
} }
node.callbacksExecuted = true node.callbacksExecuted = true
for (const name of keys) {
const errors: { message: string; error: any; html?: string }[] = []
keys.forEach((name) => {
try { try {
(this[name as keyof Callbacks] as Function)?.call(node) const callback = this[name]
} catch (err) { if (typeof callback === "function") {
if (!errors) { callback.call(node)
errors = []
} }
} catch (err) {
errors.push({ errors.push({
message: [ message: `"${name}" crashed on node ${this.type} No. ${node.ID} (${node.board}).`,
'"',
name,
'" crashed on node ',
this.type,
' No.',
node.ID,
' (',
node.board,
').',
].join(''),
error: err, error: err,
html: node.nodes?.root?.outerHTML, html: node.nodes?.root?.outerHTML,
}) })
} }
} })
if (errors) { if (errors.length) {
Main.handleErrors(errors) Main.handleErrors(errors)
} }
} }

View File

@ -3,23 +3,23 @@ import Board from './Board'
import Thread from './Thread' import Thread from './Thread'
export default class CatalogThread { export default class CatalogThread {
ID: string ID: string | number
thread: Thread thread: Thread
board: Board board: Board | string
nodes: { nodes: {
root: any root: HTMLElement
thumb: any thumb: HTMLElement
icons: any icons: HTMLElement
postCount: any postCount: number
fileCount: any fileCount: number
pageCount: any pageCount: number
replies: any replies: null
} }
toString() { toString() {
return this.ID return this.ID
} }
constructor(root, thread) { constructor(root: HTMLElement, thread: Thread) {
this.thread = thread this.thread = thread
this.ID = this.thread.ID this.ID = this.thread.ID
this.board = this.thread.board this.board = this.thread.board

View File

@ -4,7 +4,7 @@ import Board from './Board'
import Thread from './Thread' import Thread from './Thread'
export default class CatalogThreadNative { export default class CatalogThreadNative {
boardID: string | Board boardID: Board
nodes: { root: any; thumb: any } nodes: { root: any; thumb: any }
siteID: number siteID: number
threadID: number threadID: number

View File

@ -218,7 +218,7 @@ export default class Fetcher {
$.rmAll(this.root) $.rmAll(this.root)
$.add(this.root, nodes.root) $.add(this.root, nodes.root)
return $.event('PostsInserted', null, Document.apply(this.root)) return $.event('PostsInserted')
} }
fetchedPost(req: XMLHttpRequest, isCached: boolean) { fetchedPost(req: XMLHttpRequest, isCached: boolean) {

View File

@ -10,7 +10,7 @@ export default class Notice {
private closed = false private closed = false
constructor( constructor(
private type: string, type: string,
private content: string | Node, private content: string | Node,
timeout?: number, timeout?: number,
onclose?: () => void onclose?: () => void

View File

@ -473,7 +473,7 @@ export default class Post {
this.nodes.root.classList.toggle('opContainer', !isCatalogOP) this.nodes.root.classList.toggle('opContainer', !isCatalogOP)
this.nodes.post.classList.toggle('catalog-post', isCatalogOP) this.nodes.post.classList.toggle('catalog-post', isCatalogOP)
this.nodes.post.classList.toggle('op', !isCatalogOP) this.nodes.post.classList.toggle('op', !isCatalogOP)
this.nodes.post.style.left = this.nodes.post.style.right = null this.nodes.post.style.left = this.nodes.post.style.right = ''
} }
} }

View File

@ -15,7 +15,7 @@ export default class SimpleDict<T> {
return (this[key] = data) return (this[key] = data)
} }
rm(key: string | Object) { rm(key: string | object) {
if (typeof key === 'string') { if (typeof key === 'string') {
key = `${key}` key = `${key}`
if (this[key]) { if (this[key]) {

View File

@ -10,7 +10,7 @@ import SimpleDict from './SimpleDict'
*/ */
export default class Thread { export default class Thread {
board: string board: string
ID: number ID: number | string
threadID: number threadID: number
boardID: string boardID: string
siteID: string siteID: string

View File

@ -492,7 +492,7 @@ const Main = {
} }
} }
style = mainStyleSheet = styleSheets = null style = mainStyleSheet = styleSheets = ''
const setStyle = function () { const setStyle = function () {
// Use preconfigured CSS for 4chan's default themes. // Use preconfigured CSS for 4chan's default themes.
@ -779,10 +779,10 @@ const Main = {
} }
return Main.callbackNodesDB('Post', posts, function () { return Main.callbackNodesDB('Post', posts, function () {
for (thread of threads) { for (thread of threads) {
$.event('PostsInserted', null, thread.nodes.root) $.event('PostsInserted')
} }
for (thread of threadsRM) { for (thread of threadsRM) {
$.event('PostsRemoved', null, thread.nodes.root) $.event('PostsRemoved')
} }
}) })
}, },

View File

@ -595,15 +595,8 @@ $.one = function (el, events, handler) {
return $.on(el, events, cb) return $.on(el, events, cb)
} }
$.event = function (event: string, detail: any, root: Document = d) { $.event = function (type) {
if (!globalThis.chrome?.extension) { return new CustomEvent(type)
if (detail != null && typeof cloneInto === 'function') {
detail = cloneInto(detail, root.defaultView)
}
}
return root.dispatchEvent(
new CustomEvent(event, { bubbles: true, cancelable: true, detail })
)
} }
if (platform === 'userscript') { if (platform === 'userscript') {
@ -1314,7 +1307,7 @@ if (platform === 'crx') {
}) })
}) })
$.clear = function (cb: Function) { $.clear = function (cb: VoidFunction) {
// XXX https://github.com/greasemonkey/greasemonkey/issues/2033 // XXX https://github.com/greasemonkey/greasemonkey/issues/2033
// Also support case where GM_listValues is not defined. // Also support case where GM_listValues is not defined.
$.delete(Object.keys(Conf), cb) $.delete(Object.keys(Conf), cb)
@ -1322,7 +1315,7 @@ if (platform === 'crx') {
try { try {
//delete(keys, cb) //delete(keys, cb)
$.delete($.listValues(), cb) $.delete($.listValues(), cb)
} catch (error) { } } catch (error) { null }
return cb?.() return cb?.()
} }
} }

View File

@ -191,7 +191,7 @@ const CrossOrigin: ICrossOrigin = {
statusText: xhr.statusText, statusText: xhr.statusText,
responseHeaderString: xhr.responseHeaders, responseHeaderString: xhr.responseHeaders,
}) })
} catch (error) { } } catch (error) { null }
return req.onloadend() return req.onloadend()
}, },
onerror: () => req.onloadend(), onerror: () => req.onloadend(),

View File

@ -76,7 +76,7 @@ const Site = {
set(hostname: string): typeof g.SITE { set(hostname: string): typeof g.SITE {
for (const ID in Conf['siteProperties']) { for (const ID in Conf['siteProperties']) {
var site: typeof g.SITE let site: typeof g.SITE
const properties = Conf['siteProperties'][ID] const properties = Conf['siteProperties'][ID]
if (properties.canonical) { if (properties.canonical) {
continue continue

View File

@ -27,6 +27,8 @@
"esModuleInterop": true "esModuleInterop": true
}, },
"exclude": [ "exclude": [
"node_modules",
"tools",
"src/meta/*", "src/meta/*",
"dist/*" "dist/*"
] ]