diff --git a/src/Filtering/Filter.ts b/src/Filtering/Filter.ts index 32ccb7d..d75cad3 100644 --- a/src/Filtering/Filter.ts +++ b/src/Filtering/Filter.ts @@ -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( diff --git a/src/General/Index.js b/src/General/Index.js index 002afda..6d09d19 100644 --- a/src/General/Index.js +++ b/src/General/Index.js @@ -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) } diff --git a/src/General/Settings.tsx b/src/General/Settings.tsx index 7474cf8..0524622 100644 --- a/src/General/Settings.tsx +++ b/src/General/Settings.tsx @@ -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 = $( diff --git a/src/Images/FappeTyme.js b/src/Images/FappeTyme.js index 93d6f6f..81dbfab 100644 --- a/src/Images/FappeTyme.js +++ b/src/Images/FappeTyme.js @@ -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) } diff --git a/src/Images/Gallery.js b/src/Images/Gallery.js index e7b2cb0..3b0848a 100644 --- a/src/Images/Gallery.js +++ b/src/Images/Gallery.js @@ -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 ( [ diff --git a/src/Images/ImageExpand.js b/src/Images/ImageExpand.js index 8097706..9e0eaad 100644 --- a/src/Images/ImageExpand.js +++ b/src/Images/ImageExpand.js @@ -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 } }, diff --git a/src/Images/ImageHover.js b/src/Images/ImageHover.js index 5ca984d..983f873 100644 --- a/src/Images/ImageHover.js +++ b/src/Images/ImageHover.js @@ -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) }) } }, diff --git a/src/Miscellaneous/CatalogLinks.js b/src/Miscellaneous/CatalogLinks.js index b8cae98..c2a8f5d 100644 --- a/src/Miscellaneous/CatalogLinks.js +++ b/src/Miscellaneous/CatalogLinks.js @@ -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' && diff --git a/src/Miscellaneous/ExpandComment.js b/src/Miscellaneous/ExpandComment.js index a80b8cb..878f5ef 100644 --- a/src/Miscellaneous/ExpandComment.js +++ b/src/Miscellaneous/ExpandComment.js @@ -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' || diff --git a/src/Miscellaneous/ExpandThread.js b/src/Miscellaneous/ExpandThread.js index 4303f33..d3b97dc 100644 --- a/src/Miscellaneous/ExpandThread.js +++ b/src/Miscellaneous/ExpandThread.js @@ -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) diff --git a/src/Miscellaneous/FileInfo.tsx b/src/Miscellaneous/FileInfo.tsx index 3fa57a9..e645d10 100644 --- a/src/Miscellaneous/FileInfo.tsx +++ b/src/Miscellaneous/FileInfo.tsx @@ -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) || diff --git a/src/Miscellaneous/Fourchan.js b/src/Miscellaneous/Fourchan.js index 5ff9a91..5acb4de 100644 --- a/src/Miscellaneous/Fourchan.js +++ b/src/Miscellaneous/Fourchan.js @@ -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() diff --git a/src/Miscellaneous/Keybinds.js b/src/Miscellaneous/Keybinds.js index 6add819..9d4c3f2 100644 --- a/src/Miscellaneous/Keybinds.js +++ b/src/Miscellaneous/Keybinds.js @@ -567,7 +567,7 @@ var Keybinds = { ta.setSelectionRange(range, range) // Fire the 'input' event - return $.event('input', null, ta) + return $.event('input') }, sage() { diff --git a/src/Monitoring/ReplyPruning.js b/src/Monitoring/ReplyPruning.js index 3cfde1e..c114af9 100644 --- a/src/Monitoring/ReplyPruning.js +++ b/src/Monitoring/ReplyPruning.js @@ -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 diff --git a/src/classes/Board.ts b/src/classes/Board.ts index 3fd51a1..97bec4a 100644 --- a/src/classes/Board.ts +++ b/src/classes/Board.ts @@ -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 posts: SimpleDict config: diff --git a/src/classes/Callbacks.ts b/src/classes/Callbacks.ts index 50ce7f8..980f812 100644 --- a/src/classes/Callbacks.ts +++ b/src/classes/Callbacks.ts @@ -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) } } diff --git a/src/classes/CatalogThread.ts b/src/classes/CatalogThread.ts index 37761b3..91560c3 100644 --- a/src/classes/CatalogThread.ts +++ b/src/classes/CatalogThread.ts @@ -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 diff --git a/src/classes/CatalogThreadNative.ts b/src/classes/CatalogThreadNative.ts index 9f91ec9..e5b858b 100644 --- a/src/classes/CatalogThreadNative.ts +++ b/src/classes/CatalogThreadNative.ts @@ -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 diff --git a/src/classes/Fetcher.ts b/src/classes/Fetcher.ts index 07efe23..7e7392a 100644 --- a/src/classes/Fetcher.ts +++ b/src/classes/Fetcher.ts @@ -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) { diff --git a/src/classes/Notice.ts b/src/classes/Notice.ts index c33d3c6..da0352f 100644 --- a/src/classes/Notice.ts +++ b/src/classes/Notice.ts @@ -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 diff --git a/src/classes/Post.ts b/src/classes/Post.ts index ed0454f..4af9ea9 100644 --- a/src/classes/Post.ts +++ b/src/classes/Post.ts @@ -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 = '' } } diff --git a/src/classes/SimpleDict.ts b/src/classes/SimpleDict.ts index 581e977..42088c9 100644 --- a/src/classes/SimpleDict.ts +++ b/src/classes/SimpleDict.ts @@ -15,7 +15,7 @@ export default class SimpleDict { return (this[key] = data) } - rm(key: string | Object) { + rm(key: string | object) { if (typeof key === 'string') { key = `${key}` if (this[key]) { diff --git a/src/classes/Thread.ts b/src/classes/Thread.ts index 9e10014..5e841e6 100644 --- a/src/classes/Thread.ts +++ b/src/classes/Thread.ts @@ -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 diff --git a/src/main/Main.js b/src/main/Main.js index f4184ea..1870ff0 100644 --- a/src/main/Main.js +++ b/src/main/Main.js @@ -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') } }) }, diff --git a/src/platform/$.ts b/src/platform/$.ts index 102f650..09ddeff 100644 --- a/src/platform/$.ts +++ b/src/platform/$.ts @@ -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?.() } } diff --git a/src/platform/CrossOrigin.ts b/src/platform/CrossOrigin.ts index cadcbe4..d6b0534 100644 --- a/src/platform/CrossOrigin.ts +++ b/src/platform/CrossOrigin.ts @@ -191,7 +191,7 @@ const CrossOrigin: ICrossOrigin = { statusText: xhr.statusText, responseHeaderString: xhr.responseHeaders, }) - } catch (error) { } + } catch (error) { null } return req.onloadend() }, onerror: () => req.onloadend(), diff --git a/src/site/Site.ts b/src/site/Site.ts index cf65316..1e2a0d1 100644 --- a/src/site/Site.ts +++ b/src/site/Site.ts @@ -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 diff --git a/tsconfig.json b/tsconfig.json index 9c265e5..7cfe79f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,6 +27,8 @@ "esModuleInterop": true }, "exclude": [ + "node_modules", + "tools", "src/meta/*", "dist/*" ]