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.
var filter = line.replace(regexp[0], '')
const filter = line.replace(regexp[0], '')
// List of the boards this filter applies to.
const boards = this.parseBoards(

View File

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

View File

@ -713,7 +713,7 @@ Enable it on boards.${
if (compareString < '00001.00011.00019.00003' && !Settings.dialog) {
$.queueTask(() =>
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']) {
const data = Conf['selectedArchives'][boardID]
for (const type in data) {
var select
let select
const id = data[type]
if (
(select = $(

View File

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

View File

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

View File

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

View File

@ -55,7 +55,6 @@ const ImageHover = {
mouseover(post, file) {
return function (e) {
let el, height, width
// @ts-ignore
if (!doc.contains(this)) {
return
}
@ -92,7 +91,6 @@ const ImageHover = {
Volume.setup(el)
if (Conf['Autoplay']) {
el.play()
// @ts-ignore
if (this.nodeName === 'VIDEO') {
this.currentTime = el.currentTime
}
@ -144,7 +142,7 @@ const ImageHover = {
this.src = file
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
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
var CatalogLinks = {
const CatalogLinks = {
init() {
if (
g.SITE.software === 'yotsuba' &&

View File

@ -9,7 +9,7 @@ import $$ from '../platform/$$'
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
var ExpandComment = {
const ExpandComment = {
init() {
if (
g.VIEW !== 'index' ||

View File

@ -164,7 +164,7 @@ var ExpandThread = {
}
if (Index.enabled) {
// otherwise handled by Main.addPosts
$.event('PostsRemoved', null, a.parentNode)
$.event('PostsRemoved')
}
a.textContent = g.SITE.Build.summaryText('+', postsCount, filesCount)
return $.rm($('.summary-bottom', threadRoot))
@ -208,7 +208,7 @@ var ExpandThread = {
}
Main.callbackNodes('Post', posts)
$.after(a, postsRoot)
$.event('PostsInserted', null, a.parentNode)
$.event('PostsInserted')
const postsCount = postsRoot.length
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
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
var FileInfo = {
const FileInfo = {
init() {
if (
!['index', 'thread', 'archive'].includes(g.VIEW) ||

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -473,7 +473,7 @@ export default class Post {
this.nodes.root.classList.toggle('opContainer', !isCatalogOP)
this.nodes.post.classList.toggle('catalog-post', 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)
}
rm(key: string | Object) {
rm(key: string | object) {
if (typeof key === 'string') {
key = `${key}`
if (this[key]) {

View File

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

View File

@ -492,7 +492,7 @@ const Main = {
}
}
style = mainStyleSheet = styleSheets = null
style = mainStyleSheet = styleSheets = ''
const setStyle = function () {
// Use preconfigured CSS for 4chan's default themes.
@ -779,10 +779,10 @@ const Main = {
}
return Main.callbackNodesDB('Post', posts, function () {
for (thread of threads) {
$.event('PostsInserted', null, thread.nodes.root)
$.event('PostsInserted')
}
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)
}
$.event = function (event: string, detail: any, root: Document = d) {
if (!globalThis.chrome?.extension) {
if (detail != null && typeof cloneInto === 'function') {
detail = cloneInto(detail, root.defaultView)
}
}
return root.dispatchEvent(
new CustomEvent(event, { bubbles: true, cancelable: true, detail })
)
$.event = function (type) {
return new CustomEvent(type)
}
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
// Also support case where GM_listValues is not defined.
$.delete(Object.keys(Conf), cb)
@ -1322,7 +1315,7 @@ if (platform === 'crx') {
try {
//delete(keys, cb)
$.delete($.listValues(), cb)
} catch (error) { }
} catch (error) { null }
return cb?.()
}
}

View File

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

View File

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

View File

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