From d46c6e42c251046e298ea69b9e67e56831717984 Mon Sep 17 00:00:00 2001 From: Lalle <29478339+LalleSX@users.noreply.github.com> Date: Mon, 17 Apr 2023 05:53:36 +0200 Subject: [PATCH] QR types cast --- src/Posting/PostSuccessful.js | 6 -- src/Posting/{QR.js => QR.ts} | 172 ++++++++++++++++++++++++++-------- src/globals/globals.ts | 8 ++ src/platform/$$.ts | 4 +- tsconfig.json | 5 +- 5 files changed, 147 insertions(+), 48 deletions(-) rename src/Posting/{QR.js => QR.ts} (92%) diff --git a/src/Posting/PostSuccessful.js b/src/Posting/PostSuccessful.js index 73eb81b..3d3d5d2 100644 --- a/src/Posting/PostSuccessful.js +++ b/src/Posting/PostSuccessful.js @@ -2,12 +2,6 @@ import DataBoard from '../classes/DataBoard' import { Conf, d, g } from '../globals/globals' import $ from '../platform/$' -/* - * decaffeinate suggestions: - * DS101: Remove unnecessary use of Array.from - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md - */ const PostSuccessful = { init() { if (!Conf['Remember Your Posts']) { diff --git a/src/Posting/QR.js b/src/Posting/QR.ts similarity index 92% rename from src/Posting/QR.js rename to src/Posting/QR.ts index 42d7347..1d5b0ca 100644 --- a/src/Posting/QR.js +++ b/src/Posting/QR.ts @@ -24,8 +24,83 @@ import { DAY, dict, SECOND } from '../platform/helpers' * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ - -var QR = { +interface QR { + initReady(initReady: boolean): any; + postingIsEnabled: boolean; + nodes: any; + open(): unknown; + close(): unknown; + captcha: { init(): any; moreNeeded(): void; getThread(): { boardID: string; threadID: string }; setup(focus: any): any; destroy(): boolean; updateThread(): any; getOne(): {}; setUsed(): any; occupied(): boolean } | { lifetime: number; init(): void; timeouts: {}; prevNeeded: number; noscriptURL(): string; moreNeeded(): void; toggle(): any; setup(focus: any, force: any): any; setupNoscript(): any; setupJS(): any; afterSetup(mutations: any): void; setupIFrame(iframe: any): void; fixQRPosition(): string; setupTextArea(textarea: any): void; destroy(): boolean; getOne(isReply: any): any; save(pasted: any, token: any): any; count(): void; reload(): any; occupied(): boolean }; + min_width: number; + min_height: number; + max_width: number; + max_height: number; + max_size: number; + max_size_video: number; + max_comment: number; + max_width_video: number; + max_height_video: number; + max_duration_video: number; + forcedAnon: boolean; + spoiler: boolean; + link: any; + getFile(d: Document, arg1: string, getFile: any): unknown; + drawFile(d: Document, arg1: string, drawFile: any): unknown; + setFile(d: Document, arg1: string, setFile: any): unknown; + paste(d: Document, arg1: string, paste: any): unknown; + dragOver(d: Document, arg1: string, dragOver: any): unknown; + dropFile(d: Document, arg1: string, dropFile: any): unknown; + drag(d: Document, arg1: string, drag: any): unknown; + generatePostableThreadsList(d: Document, arg1: string, generatePostableThreadsList: any): unknown; + statusCheck(d: Document, arg1: string, statusCheck: any): unknown; + hide(): unknown; + posts: any; + abort(): void; + status(): void; + quote(quote: any, arg1: string, quote1: any): unknown; + unhide(): unknown; + dialog(): unknown; + shortcut(shortcut: any, arg1: string): unknown; + req: any; + cleanNotifications(): unknown; + blur(): unknown; + post: any; + cooldown: any; + inBubble(): unknown; + hasFocus: any; + texPreviewHide(): unknown; + setCustomCooldown(enabled: any): unknown; + notifications: any; + selected: any; + openPost(): unknown; + openError(): unknown; + error(div: any): unknown; + handleFiles(arg0: any[]): unknown; + extensionFromType(extensionFromType: any, type: any): unknown; + handleUrl(src: any): unknown; + handleFile(file: any, length: any): unknown; + flagsInput(): unknown; + toggleHide(autohide: any, arg1: string, toggleHide: any): unknown; + submit(status: any, arg1: string, submit: any): unknown; + toggleSJIS(sjisToggle: any, arg1: string, toggleSJIS: any): unknown; + texPreviewShow(texButton: any, arg1: string, texPreviewShow: any): unknown; + oekaki: any; + openFileInput(fileButton: any, arg1: string, openFileInput: any): unknown; + toggleCustomCooldown(customCooldown: any, arg1: string, toggleCustomCooldown: any): unknown; + focus(arg0: string, focus: any, arg2: boolean): unknown; + pasteFF: MutationCallback; + persona: any; + flags(): unknown; + response: any; + currentCaptcha: any; + connectionError(): any; + errorCount: any; + waitForThread(URL: string, open: (() => Window | VMScriptGMTabControl) | (() => string)): unknown; + characterCount(): unknown; + validExtension(validExtension: any): any; + mimeTypes: any; +} +var QR: QR = { mimeTypes: [ 'image/jpeg', 'image/png', @@ -35,8 +110,9 @@ var QR = { 'application/x-shockwave-flash', 'video/webm', ], - - validExtension: /\.(jpe?g|png|gif|pdf|swf|webm)$/i, + validExtension: function (ext: string) { + return this.mimeTypes.includes(this.typeFromExtension[ext]) + }, typeFromExtension: { jpg: 'image/jpeg', @@ -48,14 +124,21 @@ var QR = { webm: 'video/webm', }, - extensionFromType: { - 'image/jpeg': 'jpg', - 'image/png': 'png', - 'image/gif': 'gif', - 'application/pdf': 'pdf', - 'application/vnd.adobe.flash.movie': 'swf', - 'application/x-shockwave-flash': 'swf', - 'video/webm': 'webm', + extensionFromType: function (type: string) { + switch (type) { + case 'image/jpeg': + return 'jpg' + case 'image/png': + return 'png' + case 'image/gif': + return 'gif' + case 'application/pdf': + return 'pdf' + case 'application/vnd.adobe.flash.movie': + return 'swf' + case 'video/webm': + return 'webm' + } }, init() { @@ -66,7 +149,7 @@ var QR = { this.posts = [] - $.on(d, '4chanXInitFinished', () => BoardConfig.ready(QR.initReady)) + $.on(d, '4chanXInitFinished', () => BoardConfig.ready(QR.initReady)) Callbacks.Post.push({ name: 'Quick Reply', @@ -200,7 +283,8 @@ var QR = { open() { if (QR.nodes) { if (QR.nodes.el.hidden) { - QR.captcha.setup() + QR.nodes.el.hidden = false + QR.unhide() } QR.nodes.el.hidden = false QR.unhide() @@ -944,8 +1028,7 @@ var QR = { QR.abort() return } - - $.forceSync('cooldowns') + $.forceSync() if (QR.cooldown.seconds) { if (force) { QR.cooldown.clear() @@ -988,7 +1071,7 @@ var QR = { } if ( - QR.captcha.isEnabled && + QR.captcha && !(QR.captcha === Captcha.v2 && /\b_ct=/.test(d.cookie) && threadID) && !(err && !force) ) { @@ -1000,9 +1083,7 @@ var QR = { } if (!captcha) { err = 'No valid captcha.' - QR.captcha.setup( - !QR.cooldown.auto || d.activeElement === QR.nodes.status, - ) + QR.captcha.setup(!QR.cooldown.auto || d.activeElement === QR.nodes.status, true) } } @@ -1942,6 +2023,22 @@ var QR = { }, post: class { + nodes: { el: any; rm: any; spoiler: any; span: any } + spoiler: any + thread: string | number + name: any + email: any + sub: any + flag: any + isLocked: boolean + file: any + com: any + quotedText: string + errors: any[] + filename: any + filesize: string + pasting: boolean + draggable: any constructor(select) { this.select = this.select.bind(this) const el = $.el('a', { @@ -2049,6 +2146,9 @@ var QR = { URL.revokeObjectURL(this.URL) return this.dismissErrors() } + URL(URL: any) { + throw new Error('Method not implemented.') + } lock(lock = true) { this.isLocked = lock @@ -2375,14 +2475,10 @@ var QR = { this.nodes.el.dataset.height = height this.nodes.el.dataset.width = width if (height > QR.max_height || width > QR.max_width) { - this.fileError( - `Image too large (image: ${height}x${width}px, max: ${QR.max_height}x${QR.max_width}px)`, - ) + this.fileError(`Image too large (image: ${height}x${width}px, max: ${QR.max_height}x${QR.max_width}px)`, meta.faq + '#image-too-large') } if (height < QR.min_height || width < QR.min_width) { - return this.fileError( - `Image too small (image: ${height}x${width}px, min: ${QR.min_height}x${QR.min_width}px)`, - ) + return this.fileError(`Image too small (image: ${height}x${width}px, min: ${QR.min_height}x${QR.min_width}px)`, meta.faq + '#image-too-small') } } else { const { videoHeight, videoWidth, duration } = el @@ -2392,24 +2488,18 @@ var QR = { const max_height = Math.min(QR.max_height, QR.max_height_video) const max_width = Math.min(QR.max_width, QR.max_width_video) if (videoHeight > max_height || videoWidth > max_width) { - this.fileError( - `Video too large (video: ${videoHeight}x${videoWidth}px, max: ${max_height}x${max_width}px)`, - ) + this.fileError(`Video too large (video: ${videoHeight}x${videoWidth}px, max: ${max_height}x${max_width}px)`, meta.faq + '#video-too-large') } if (videoHeight < QR.min_height || videoWidth < QR.min_width) { - this.fileError( - `Video too small (video: ${videoHeight}x${videoWidth}px, min: ${QR.min_height}x${QR.min_width}px)`, - ) + this.fileError(`Video too small (video: ${videoHeight}x${videoWidth}px, min: ${QR.min_height}x${QR.min_width}px)`, meta.faq + '#video-too-small') } if (!isFinite(duration)) { - this.fileError('Video lacks duration metadata (try remuxing)') + this.fileError ('Video has no duration', meta.faq + '#video-has-no-duration') } else if (duration > QR.max_duration_video) { - this.fileError( - `Video too long (video: ${duration}s, max: ${QR.max_duration_video}s)`, - ) + this.fileError(`Video too long (video: ${duration}s, max: ${QR.max_duration_video}s)`, meta.faq + '#video-too-long') } if (BoardConfig.noAudio(g.BOARD.ID) && $.hasAudio(el)) { - return this.fileError('Audio not allowed') + return this.fileError('Audio not allowed', meta.faq + '#audio-not-allowed') } } } @@ -2471,7 +2561,7 @@ var QR = { $.rmClass(this.nodes.el, 'has-file') this.showFileData() URL.revokeObjectURL(this.URL) - this.dismissErrors((error) => $.hasClass(error, 'file-error')) + this.dismissErrors() return this.preventAutoPost() } @@ -2536,6 +2626,9 @@ var QR = { e.dataTransfer.setDragImage(this, e.clientX - left, e.clientY - top) return $.addClass(this, 'drag') } + getBoundingClientRect(): { left: any; top: any } { + throw new Error('Method not implemented.') + } dragEnd() { return $.rmClass(this, 'drag') @@ -2570,6 +2663,9 @@ var QR = { QR.status() return QR.captcha.updateThread?.() } + parentNode(arg0: string, parentNode: any) { + throw new Error('Method not implemented.') + } }, } export default QR diff --git a/src/globals/globals.ts b/src/globals/globals.ts index 6331be1..a0ec989 100644 --- a/src/globals/globals.ts +++ b/src/globals/globals.ts @@ -7,6 +7,13 @@ import type SWTinyboard from '../site/SW.tinyboard' // interfaces might be incomplete export interface BoardConfig { + forced_anon: any + sjis_tags: any + math_tags: any + country_flags: any + board_flags: any + require_subject: any + text_only: any board: string bump_limit: number cooldowns: { @@ -30,6 +37,7 @@ export interface BoardConfig { } export interface Board { + cooldowns(): any ID: string boardID: string siteID: string diff --git a/src/platform/$$.ts b/src/platform/$$.ts index 83d413f..cbee49d 100644 --- a/src/platform/$$.ts +++ b/src/platform/$$.ts @@ -1,6 +1,4 @@ import { d } from '../globals/globals'; -const $$ = (selector: string, root: HTMLElement | null = d.body): Element[] => - Array.from(root?.querySelectorAll(selector) ?? []) as Element[]; - +const $$ = (selector: string, root = d.body) => [...Array.from(root.querySelectorAll(selector))]; export default $$; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index e8f32ff..76fd7a4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,9 @@ "outDir": "builds/test/crx/tsOutput", }, "exclude": [ - "builds/test/tsOutput" + "builds/test/tsOutput", + "src/meta/*", + "./tools/*", + "dist/*" ] }