From caf419b8e1503332caca020a2e1843d68c12e842 Mon Sep 17 00:00:00 2001 From: xpadev Date: Tue, 30 Apr 2024 13:24:18 +0900 Subject: [PATCH] fix: biome error --- src/comments/BaseComment.ts | 14 ++++---- src/comments/FlashComment.ts | 32 +++++++++--------- src/comments/HTML5Comment.ts | 8 ++--- src/definition/initConfig.ts | 24 ++++++++++---- src/eventHandler.ts | 14 ++++---- src/input/legacy.ts | 4 +-- src/input/legacyOwner.ts | 9 ++--- src/input/owner.ts | 14 ++++---- src/input/v1.ts | 8 ++--- src/input/xml2js.ts | 4 +-- src/input/xmlDocument.ts | 4 +-- src/main.ts | 32 +++++++++--------- src/renderer/canvas.ts | 11 ++++--- src/utils/array.ts | 5 +-- src/utils/color.ts | 23 ++++++------- src/utils/comment.ts | 64 +++++++++++++++++++++--------------- src/utils/commentArt.ts | 8 ++--- src/utils/flash.ts | 27 ++++++++------- src/utils/niconico.ts | 28 ++++++++-------- src/utils/sort.ts | 6 ++-- 20 files changed, 187 insertions(+), 152 deletions(-) diff --git a/src/comments/BaseComment.ts b/src/comments/BaseComment.ts index b2f2ff0e..f8616a11 100755 --- a/src/comments/BaseComment.ts +++ b/src/comments/BaseComment.ts @@ -281,7 +281,7 @@ class BaseComment implements IComment { this.image = cache.image; window.setTimeout( () => { - delete this.image; + this.image = undefined; }, this.comment.long * 10 + config.cacheAge, ); @@ -317,7 +317,7 @@ class BaseComment implements IComment { this.image = image; window.setTimeout( () => { - delete this.image; + this.image = undefined; }, this.comment.long * 10 + config.cacheAge, ); @@ -352,11 +352,11 @@ class BaseComment implements IComment { } protected getCacheKey() { - return ( - JSON.stringify(this.comment.content) + - `@@${this.pluginName}@@` + - [...this.comment.mail].sort((a, b) => a.localeCompare(b)).join(",") - ); + return `${JSON.stringify(this.comment.content)}@@${this.pluginName}@@${[ + ...this.comment.mail, + ] + .sort((a, b) => a.localeCompare(b)) + .join(",")}`; } } diff --git a/src/comments/FlashComment.ts b/src/comments/FlashComment.ts index a66ddf7a..554cc15b 100755 --- a/src/comments/FlashComment.ts +++ b/src/comments/FlashComment.ts @@ -58,7 +58,7 @@ class FlashComment extends BaseComment { } this.comment = this.getCommentSize(comment); this.cacheKey = this.getCacheKey(); - delete this.image; + this.image = undefined; } override convertComment(comment: FormattedComment): FormattedCommentWithSize { @@ -169,9 +169,9 @@ class FlashComment extends BaseComment { override measureText(comment: MeasureTextInput): MeasureTextResult { //ref: https://github.com/Saccubus/Saccubus1/blob/master/vhook/src/comment/com_surface.c - const configLineHeight = getConfig(config.lineHeight, true), - configFontSize = getConfig(config.fontSize, true)[comment.size], - configStageSize = getConfig(config.commentStageSize, true); + const configLineHeight = getConfig(config.lineHeight, true); + const configFontSize = getConfig(config.fontSize, true)[comment.size]; + const configStageSize = getConfig(config.commentStageSize, true); const defaultFontSize = configFontSize.default; comment.lineHeight ??= configLineHeight[comment.size].default; const widthLimit = configStageSize[comment.full ? "fullWidth" : "width"]; @@ -263,10 +263,10 @@ class FlashComment extends BaseComment { } private _measureContent(comment: MeasureTextInput) { - const widthArr: number[] = [], - spacedWidthArr: number[] = []; - let currentWidth = 0, - spacedWidth = 0; + const widthArr: number[] = []; + const spacedWidthArr: number[] = []; + let currentWidth = 0; + let spacedWidth = 0; for (const item of comment.content) { if (item.type === "spacer") { spacedWidth += @@ -303,9 +303,9 @@ class FlashComment extends BaseComment { spacedWidthArr.push(spacedWidth); item.width = widths; } - const leadLine = (function () { - let max = 0, - index = -1; + const leadLine = (() => { + let max = 0; + let index = -1; spacedWidthArr.forEach((val, i) => { if (max < val) { max = val; @@ -342,7 +342,7 @@ class FlashComment extends BaseComment { this.comment.resizedY ? "resized" : "default" ]) * this.comment.scale; - this.renderer.setStrokeStyle(`rgba(255,255,0,0.25)`); + this.renderer.setStrokeStyle("rgba(255,255,0,0.25)"); this.renderer.strokeRect( posX, posY + linePosY * this._globalScale, @@ -371,10 +371,10 @@ class FlashComment extends BaseComment { this.comment.fontSize * this.comment.lineHeight * config.flashCommentYOffset[this.comment.size][offsetKey]; - let lastFont = this.comment.font, - leftOffset = 0, - lineCount = 0, - isLastButton = false; + let lastFont = this.comment.font; + let leftOffset = 0; + let lineCount = 0; + let isLastButton = false; for (const item of this.comment.content) { if (item.type === "spacer") { leftOffset += item.count * item.charWidth * this.comment.fontSize; diff --git a/src/comments/HTML5Comment.ts b/src/comments/HTML5Comment.ts index e25c0858..eebea104 100755 --- a/src/comments/HTML5Comment.ts +++ b/src/comments/HTML5Comment.ts @@ -47,7 +47,7 @@ class HTML5Comment extends BaseComment { }; this.comment = this.getCommentSize(comment); this.cacheKey = this.getCacheKey(); - delete this.image; + this.image = undefined; } override convertComment(comment: FormattedComment): FormattedCommentWithSize { @@ -129,9 +129,9 @@ class HTML5Comment extends BaseComment { override measureText(comment: MeasureTextInput): MeasureTextResult { const scale = getConfig(config.commentScale, false); - const configFontSize = getConfig(config.fontSize, false), - lineHeight = getLineHeight(comment.size, false), - charSize = getCharSize(comment.size, false); + const configFontSize = getConfig(config.fontSize, false); + const lineHeight = getLineHeight(comment.size, false); + const charSize = getCharSize(comment.size, false); if (!comment.lineHeight) comment.lineHeight = lineHeight; if (!comment.charSize) comment.charSize = charSize; comment.fontSize = comment.charSize * 0.8; diff --git a/src/definition/initConfig.ts b/src/definition/initConfig.ts index fcdfd950..aa5b0080 100755 --- a/src/definition/initConfig.ts +++ b/src/definition/initConfig.ts @@ -9,15 +9,25 @@ import { isFlashComment } from "@/utils/comment"; * コンフィグを初期化する */ const initConfig = () => { - const platform: Platform = (function (ua) { - if (RegExp(/windows nt 6\.[12]/i).exec(ua)) return "win7"; - else if (RegExp(/windows nt (6\.3|10\.\d+)|win32/i).exec(ua)) + const platform: Platform = ((ua) => { + if (RegExp(/windows nt 6\.[12]/i).exec(ua)) { + return "win7"; + } + if (RegExp(/windows nt (6\.3|10\.\d+)|win32/i).exec(ua)) { return "win8_1"; - else if (RegExp(/windows nt/i).exec(ua)) return "win"; - else if (RegExp(/mac os x 10(.|_)(9|10)/i).exec(ua)) return "mac10_9"; - else if (RegExp(/mac os x 10(.|_)\d{2}|darwin/i).exec(ua)) + } + if (RegExp(/windows nt/i).exec(ua)) { + return "win"; + } + if (RegExp(/mac os x 10(.|_)(9|10)/i).exec(ua)) { + return "mac10_9"; + } + if (RegExp(/mac os x 10(.|_)\d{2}|darwin/i).exec(ua)) { return "mac10_11"; - else if (RegExp(/mac os x/i).exec(ua)) return "mac"; + } + if (RegExp(/mac os x/i).exec(ua)) { + return "mac"; + } return "other"; })(typeof navigator !== "undefined" ? navigator.userAgent : process.platform); const defaultConfig: BaseConfig = { diff --git a/src/eventHandler.ts b/src/eventHandler.ts index e0231da6..5991d8c7 100755 --- a/src/eventHandler.ts +++ b/src/eventHandler.ts @@ -78,8 +78,8 @@ const processCommentDisableScript = (vpos: number, lastVpos: number) => { if (handlerCounts.commentDisable < 1 && handlerCounts.commentEnable < 1) return; for (const range of nicoScripts.ban) { - const vposInRange = range.start < vpos && vpos < range.end, - lastVposInRange = range.start < lastVpos && lastVpos < range.end; + const vposInRange = range.start < vpos && vpos < range.end; + const lastVposInRange = range.start < lastVpos && lastVpos < range.end; if (vposInRange && !lastVposInRange) { executeEvents("commentDisable", { type: "commentDisable", @@ -104,8 +104,8 @@ const processCommentDisableScript = (vpos: number, lastVpos: number) => { const processSeekDisableScript = (vpos: number, lastVpos: number) => { if (handlerCounts.seekDisable < 1 && handlerCounts.seekEnable < 1) return; for (const range of nicoScripts.seekDisable) { - const vposInRange = range.start < vpos && vpos < range.end, - lastVposInRange = range.start < lastVpos && lastVpos < range.end; + const vposInRange = range.start < vpos && vpos < range.end; + const lastVposInRange = range.start < lastVpos && lastVpos < range.end; if (vposInRange && !lastVposInRange) { executeEvents("seekDisable", { type: "seekDisable", @@ -130,9 +130,9 @@ const processSeekDisableScript = (vpos: number, lastVpos: number) => { const processJumpScript = (vpos: number, lastVpos: number) => { if (handlerCounts.jump < 1) return; for (const range of nicoScripts.jump) { - const vposInRange = range.start < vpos && (!range.end || vpos < range.end), - lastVposInRange = - range.start < lastVpos && (!range.end || lastVpos < range.end); + const vposInRange = range.start < vpos && (!range.end || vpos < range.end); + const lastVposInRange = + range.start < lastVpos && (!range.end || lastVpos < range.end); if (vposInRange && !lastVposInRange) { executeEvents("jump", { type: "jump", diff --git a/src/input/legacy.ts b/src/input/legacy.ts index 2af662d2..9f77a6c7 100644 --- a/src/input/legacy.ts +++ b/src/input/legacy.ts @@ -21,8 +21,8 @@ export const LegacyParser: InputParser = { * @returns 変換後のデータ */ const fromLegacy = (data: RawApiResponse[]): FormattedComment[] => { - const data_: FormattedComment[] = [], - userList: string[] = []; + const data_: FormattedComment[] = []; + const userList: string[] = []; for (const _val of data) { const val = safeParse(ZApiChat, _val.chat); if (!val.success) continue; diff --git a/src/input/legacyOwner.ts b/src/input/legacyOwner.ts index 13e367a6..bc1646b8 100644 --- a/src/input/legacyOwner.ts +++ b/src/input/legacyOwner.ts @@ -1,5 +1,5 @@ import type { InputParser } from "@/@types"; -import { type FormattedComment } from "@/@types"; +import type { FormattedComment } from "@/@types"; import { InvalidFormatError } from "@/errors"; import typeGuard from "@/typeGuard"; @@ -17,15 +17,16 @@ export const LegacyOwnerParser: InputParser = { * @returns 変換後のデータ */ const fromLegacyOwner = (data: string): FormattedComment[] => { - const data_: FormattedComment[] = [], - comments = data.split("\n"); + const data_: FormattedComment[] = []; + const comments = data.split("\n"); for (let i = 0, n = comments.length; i < n; i++) { const value = comments[i]; if (!value) continue; const commentData = value.split(":"); if (commentData.length < 3) { continue; - } else if (commentData.length > 3) { + } + if (commentData.length > 3) { for (let j = 3, n = commentData.length; j < n; j++) { commentData[2] += `:${commentData[j]}`; } diff --git a/src/input/owner.ts b/src/input/owner.ts index f3ba34cd..38c933e4 100644 --- a/src/input/owner.ts +++ b/src/input/owner.ts @@ -65,16 +65,18 @@ const time2vpos = (input: string): number => { ) { return ( (Number(time[1]) * 60 + Number(time[2])) * 100 + - Number(time[3]) / Math.pow(10, time[3].length - 2) + Number(time[3]) / 10 ** (time[3].length - 2) ); - } else if (time[4] !== undefined && time[5] !== undefined) { + } + if (time[4] !== undefined && time[5] !== undefined) { return (Number(time[4]) * 60 + Number(time[5])) * 100; - } else if (time[6] !== undefined && time[7] !== undefined) { + } + if (time[6] !== undefined && time[7] !== undefined) { return ( - Number(time[6]) * 100 + - Number(time[7]) / Math.pow(10, time[7].length - 2) + Number(time[6]) * 100 + Number(time[7]) / 10 ** (time[7].length - 2) ); - } else if (time[8] !== undefined) { + } + if (time[8] !== undefined) { return Number(time[8]) * 100; } } diff --git a/src/input/v1.ts b/src/input/v1.ts index a636674a..a15700e7 100644 --- a/src/input/v1.ts +++ b/src/input/v1.ts @@ -17,11 +17,11 @@ export const V1Parser: InputParser = { * @returns 変換後のデータ */ const fromV1 = (data: V1Thread[]): FormattedComment[] => { - const data_: FormattedComment[] = [], - userList: string[] = []; + const data_: FormattedComment[] = []; + const userList: string[] = []; for (const item of data) { - const val = item.comments, - forkName = item.fork; + const val = item.comments; + const forkName = item.fork; for (const value of val) { const tmpParam: FormattedComment = { id: value.no, diff --git a/src/input/xml2js.ts b/src/input/xml2js.ts index 043c47d6..0882546c 100644 --- a/src/input/xml2js.ts +++ b/src/input/xml2js.ts @@ -11,8 +11,8 @@ export const Xml2jsParser: InputParser = { }; const fromXml2js = (data: Xml2jsPacket): FormattedComment[] => { - const data_: FormattedComment[] = [], - userList: string[] = []; + const data_: FormattedComment[] = []; + const userList: string[] = []; let index = data.packet.chat.length; for (const item of data.packet.chat) { const tmpParam: FormattedComment = { diff --git a/src/input/xmlDocument.ts b/src/input/xmlDocument.ts index 04eca072..17f1065d 100644 --- a/src/input/xmlDocument.ts +++ b/src/input/xmlDocument.ts @@ -16,8 +16,8 @@ export const XmlDocumentParser: InputParser = { * @returns 変換後のデータ */ const parseXMLDocument = (data: XMLDocument): FormattedComment[] => { - const data_: FormattedComment[] = [], - userList: string[] = []; + const data_: FormattedComment[] = []; + const userList: string[] = []; let index = Array.from(data.documentElement.children).length; for (const item of Array.from(data.documentElement.children)) { if (item.nodeName !== "chat") continue; diff --git a/src/main.ts b/src/main.ts index e109a2b2..7e7a85d5 100755 --- a/src/main.ts +++ b/src/main.ts @@ -3,9 +3,9 @@ import type { CommentEventHandlerMap, FormattedComment, IComment, - InputFormat, IPluginList, IRenderer, + InputFormat, Options, Position, Timeline, @@ -76,7 +76,7 @@ class NiconiComments { * @param initOptions 初期化オプション */ constructor( - renderer: IRenderer | HTMLCanvasElement, + _renderer: IRenderer | HTMLCanvasElement, data: InputFormat, initOptions: Options = {}, ) { @@ -89,6 +89,7 @@ class NiconiComments { setIsDebug(options.debug); resetImageCache(); resetNicoScripts(); + let renderer = _renderer; if (renderer instanceof HTMLCanvasElement) { renderer = new CanvasRenderer(renderer, options.video); } else if (options.video) { @@ -149,10 +150,11 @@ class NiconiComments { /** * 事前に当たり判定を考慮してコメントの描画場所を決定する - * @param rawData コメントデータ + * @param _rawData コメントデータ * @returns コメントのインスタンス配列 */ - private preRendering(rawData: FormattedComment[]) { + private preRendering(_rawData: FormattedComment[]) { + let rawData = _rawData; const preRenderingStart = performance.now(); if (options.keepCA) { rawData = changeCALayer(rawData); @@ -192,7 +194,7 @@ class NiconiComments { * @param end 終了インデックス * @param lazy 遅延処理を行うか */ - private getCommentPos(data: IComment[], end: number, lazy: boolean = false) { + private getCommentPos(data: IComment[], end: number, lazy = false) { const getCommentPosStart = performance.now(); if (this.processedCommentIndex + 1 >= end) return; for (const comment of data.slice(this.processedCommentIndex, end)) { @@ -225,8 +227,8 @@ class NiconiComments { for (const vpos of Object.keys(this.timeline)) { const item = this.timeline[Number(vpos)]; if (!item) continue; - const owner: IComment[] = [], - user: IComment[] = []; + const owner: IComment[] = []; + const user: IComment[] = []; for (const comment of item) { if (comment?.owner) { owner.push(comment); @@ -296,11 +298,11 @@ class NiconiComments { this.timeline[this.lastVposInt]?.filter((item) => item.loc === "naka") ?.length === 0 ) { - const current = timelineRange.filter((item) => item.loc !== "naka"), - last = - this.timeline[this.lastVposInt]?.filter( - (item) => item.loc !== "naka", - ) ?? []; + const current = timelineRange.filter((item) => item.loc !== "naka"); + const last = + this.timeline[this.lastVposInt]?.filter( + (item) => item.loc !== "naka", + ) ?? []; if (arrayEqual(current, last)) return false; } this.renderer.clearRect(0, 0, config.canvasWidth, config.canvasHeight); @@ -311,7 +313,7 @@ class NiconiComments { plugin.instance.draw?.(vpos); this.renderer.drawImage(plugin.canvas, 0, 0); } catch (e) { - console.error(`Failed to draw comments`, e); + console.error("Failed to draw comments", e); } } this._drawCollision(vposInt); @@ -367,8 +369,8 @@ class NiconiComments { private _drawCollision(vpos: number) { if (this.showCollision) { this.renderer.save(); - const leftCollision = this.collision.left[vpos], - rightCollision = this.collision.right[vpos]; + const leftCollision = this.collision.left[vpos]; + const rightCollision = this.collision.right[vpos]; this.renderer.setFillStyle("red"); if (leftCollision) { for (const comment of leftCollision) { diff --git a/src/renderer/canvas.ts b/src/renderer/canvas.ts index d146ce06..d5f6a719 100644 --- a/src/renderer/canvas.ts +++ b/src/renderer/canvas.ts @@ -23,16 +23,17 @@ class CanvasRenderer implements IRenderer { drawVideo(enableLegacyPip: boolean) { if (this.video) { - let scale; - const height = this.canvas.height / this.video.videoHeight, - width = this.canvas.width / this.video.videoWidth; + let scale: number; + const height = this.canvas.height / this.video.videoHeight; + const width = this.canvas.width / this.video.videoWidth; if (enableLegacyPip ? height > width : height < width) { scale = width; } else { scale = height; } - const offsetX = (this.canvas.width - this.video.videoWidth * scale) * 0.5, - offsetY = (this.canvas.height - this.video.videoHeight * scale) * 0.5; + const offsetX = (this.canvas.width - this.video.videoWidth * scale) * 0.5; + const offsetY = + (this.canvas.height - this.video.videoHeight * scale) * 0.5; this.context.drawImage( this.video, offsetX, diff --git a/src/utils/array.ts b/src/utils/array.ts index c2ab7ebe..22fcca2a 100755 --- a/src/utils/array.ts +++ b/src/utils/array.ts @@ -2,15 +2,16 @@ import type { IComment } from "@/@types"; /** * phpのarray_push的なあれ - * @param array 追加対象の配列 + * @param _array 追加対象の配列 * @param key 追加対象のキー * @param push 追加する値 */ const arrayPush = ( - array: { [key: number]: IComment[] }, + _array: { [key: number]: IComment[] }, key: string | number, push: IComment, ) => { + let array = _array; if (!array) { array = {}; } diff --git a/src/utils/color.ts b/src/utils/color.ts index be58512b..bbb8ba8f 100755 --- a/src/utils/color.ts +++ b/src/utils/color.ts @@ -3,10 +3,11 @@ import { config } from "@/definition/config"; /** * Hexからrgbに変換する(_live用) - * @param hex カラコ + * @param _hex カラコ * @returns RGB */ -const hex2rgb = (hex: string) => { +const hex2rgb = (_hex: string) => { + let hex = _hex; if (hex.startsWith("#")) hex = hex.slice(1); if (hex.length === 3) hex = @@ -17,18 +18,17 @@ const hex2rgb = (hex: string) => { hex.slice(2, 3) + hex.slice(2, 3); - return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map( - function (str) { - return parseInt(str, 16); - }, + return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((str) => + Number.parseInt(str, 16), ); }; /** * Hexからrgbaに変換する(_live用) - * @param hex カラコ + * @param _hex カラコ * @returns RGB */ -const hex2rgba = (hex: string) => { +const hex2rgba = (_hex: string) => { + let hex = _hex; if (hex.startsWith("#")) hex = hex.slice(1); if (hex.length === 4) hex = @@ -47,8 +47,8 @@ const hex2rgba = (hex: string) => { hex.slice(4, 6), hex.slice(4, 6), ].map((str, index) => { - if (index === 3) return parseInt(str, 16) / 256; - return parseInt(str, 16); + if (index === 3) return Number.parseInt(str, 16) / 256; + return Number.parseInt(str, 16); }); }; @@ -63,7 +63,8 @@ const getStrokeColor = (comment: FormattedCommentWithSize) => { const length = color.length; if (length === 3 || length === 6) { return `rgba(${hex2rgb(color).join(",")},${config.contextStrokeOpacity})`; - } else if (length === 4 || length === 8) { + } + if (length === 4 || length === 8) { return `rgba(${hex2rgba(color).join(",")})`; } } diff --git a/src/utils/comment.ts b/src/utils/comment.ts index 912cf296..1edbd933 100755 --- a/src/utils/comment.ts +++ b/src/utils/comment.ts @@ -47,10 +47,10 @@ const getDefaultCommand = (vpos: number): DefaultCommand => { nicoScripts.default = nicoScripts.default.filter( (item) => !item.long || item.start + item.long >= vpos, ); - let color = undefined, - size: CommentSize | undefined = undefined, - font = undefined, - loc: CommentLoc | undefined = undefined; + let color = undefined; + let size: CommentSize | undefined = undefined; + let font = undefined; + let loc: CommentLoc | undefined = undefined; for (const item of nicoScripts.default) { if (item.loc) { loc = item.loc; @@ -108,10 +108,18 @@ const applyNicoScriptReplace = ( } else { comment.content = item.replace; } - item.loc && (commands.loc = item.loc); - item.color && (commands.color = item.color); - item.size && (commands.size = item.size); - item.font && (commands.font = item.font); + if (item.loc) { + commands.loc = item.loc; + } + if (item.color) { + commands.color = item.color; + } + if (item.size) { + commands.size = item.size; + } + if (item.font) { + commands.font = item.font; + } } }; @@ -154,11 +162,11 @@ const parseCommandAndNicoScript = ( * @returns パース後の文字列 */ const parseBrackets = (input: string) => { - const content = input.split(""), - result = []; - let quote = "", - lastChar = "", - string = ""; + const content = input.split(""); + const result = []; + let quote = ""; + let lastChar = ""; + let string = ""; for (const i of content) { if (RegExp(/^["'\u300c]$/).exec(i) && quote === "") { //["'「] @@ -430,8 +438,8 @@ const processAtButton = ( * @returns パースしたコマンド */ const parseCommands = (comment: FormattedComment): ParsedCommand => { - const commands = comment.mail, - isFlash = isFlashComment(comment); + const commands = comment.mail; + const isFlash = isFlashComment(comment); const result: ParsedCommand = { loc: undefined, size: undefined, @@ -526,7 +534,8 @@ const getColor = (match: RegExpMatchArray | null) => { const value = match[1]; if (typeGuard.comment.color(value)) { return colors[value]; - } else if (typeGuard.comment.colorCodeAllowAlpha(value)) { + } + if (typeGuard.comment.colorCodeAllowAlpha(value)) { return value; } return; @@ -591,7 +600,7 @@ const processFixedComment = ( comment: IComment, collision: CollisionItem, timeline: Timeline, - lazy: boolean = false, + lazy = false, ) => { const posY = lazy ? -1 : getFixedPosY(comment, collision); for (let j = 0; j < comment.long; j++) { @@ -614,7 +623,7 @@ const processMovableComment = ( comment: IComment, collision: Collision, timeline: Timeline, - lazy: boolean = false, + lazy = false, ) => { const beforeVpos = Math.round(-288 / ((1632 + comment.width) / (comment.long + 125))) - 100; @@ -643,9 +652,9 @@ const processMovableComment = ( }; const getFixedPosY = (comment: IComment, collision: CollisionItem) => { - let posY = 0, - isChanged = true, - count = 0; + let posY = 0; + let isChanged = true; + let count = 0; while (isChanged && count < 10) { isChanged = false; count++; @@ -707,20 +716,23 @@ const getMovablePosY = ( /** * 当たり判定からコメントを配置できる場所を探す - * @param currentPos 現在のy座標 + * @param _currentPos 現在のy座標 * @param targetComment 対象コメント * @param collision 当たり判定 - * @param isChanged 位置が変更されたか + * @param _isChanged 位置が変更されたか * @returns 現在地、更新されたか、終了すべきか */ const getPosY = ( - currentPos: number, + _currentPos: number, targetComment: IComment, collision: IComment[] | undefined, - isChanged = false, + _isChanged = false, ): { currentPos: number; isChanged: boolean; isBreak: boolean } => { let isBreak = false; - if (!collision) return { currentPos, isChanged, isBreak }; + if (!collision) + return { currentPos: _currentPos, isChanged: _isChanged, isBreak }; + let currentPos = _currentPos; + let isChanged = _isChanged; for (const collisionItem of collision) { if (collisionItem.index === targetComment.index || collisionItem.posY < 0) continue; diff --git a/src/utils/commentArt.ts b/src/utils/commentArt.ts index 5d42696d..637b8ca3 100755 --- a/src/utils/commentArt.ts +++ b/src/utils/commentArt.ts @@ -75,10 +75,10 @@ const removeDuplicateCommentArt = (comments: FormattedComment[]) => { const index: { [key: string]: FormattedComment } = {}; return comments.filter((comment) => { const key = `${comment.content}@@${[...comment.mail] - .sort((a, b) => a.localeCompare(b)) - .filter((e) => !RegExp(/@[\d.]+|184|device:.+|patissier|ca/).exec(e)) - .join("")}`, - lastComment = index[key]; + .sort((a, b) => a.localeCompare(b)) + .filter((e) => !RegExp(/@[\d.]+|184|device:.+|patissier|ca/).exec(e)) + .join("")}`; + const lastComment = index[key]; if (lastComment === undefined) { index[key] = comment; return true; diff --git a/src/utils/flash.ts b/src/utils/flash.ts index c4bc61f1..0872629c 100755 --- a/src/utils/flash.ts +++ b/src/utils/flash.ts @@ -25,17 +25,20 @@ const getFlashFontIndex = (part: string): CommentContentIndex[] => { gothic: new RegExp(config.flashChar.gothic), }; const index: CommentContentIndex[] = []; - let match; - if ((match = regex.simsunStrong.exec(part)) !== null) { + let match = regex.simsunStrong.exec(part); + if (match !== null) { index.push({ font: "simsunStrong", index: match.index }); } - if ((match = regex.simsunWeak.exec(part)) !== null) { + match = regex.simsunWeak.exec(part); + if (match !== null) { index.push({ font: "simsunWeak", index: match.index }); } - if ((match = regex.gulim.exec(part)) !== null) { + match = regex.gulim.exec(part); + if (match !== null) { index.push({ font: "gulim", index: match.index }); } - if ((match = regex.gothic.exec(part)) !== null) { + match = regex.gothic.exec(part); + if (match !== null) { index.push({ font: "gothic", index: match.index }); } return index; @@ -178,8 +181,8 @@ const parseMultiFontFullWidthPart = ( if (config.flashMode === "xp") { let offset = 0; for (let i = 1, n = index.length; i < n; i++) { - const currentVal = index[i], - lastVal = index[i - 1]; + const currentVal = index[i]; + const lastVal = index[i - 1]; if (currentVal === undefined || lastVal === undefined) continue; const content = part.slice(offset, currentVal.index); addPartToResult(lineContent, content, getFlashFontName(lastVal.font)); @@ -192,8 +195,8 @@ const parseMultiFontFullWidthPart = ( } return; } - const firstVal = index[0], - secondVal = index[1]; + const firstVal = index[0]; + const secondVal = index[1]; if (!firstVal || !secondVal) { addPartToResult(lineContent, part); return; @@ -227,9 +230,9 @@ const getButtonParts = ( comment.fontSize * comment.lineHeight * config.flashCommentYOffset[comment.size][offsetKey]; - let leftOffset = 0, - lineCount = 0, - isLastButton = false; + let leftOffset = 0; + let lineCount = 0; + let isLastButton = false; for (const item of comment.content) { if (item.type === "spacer") { leftOffset += item.count * comment.fontSize * item.charWidth; diff --git a/src/utils/niconico.ts b/src/utils/niconico.ts index 842ead95..e3a7a031 100755 --- a/src/utils/niconico.ts +++ b/src/utils/niconico.ts @@ -23,10 +23,11 @@ const getLineHeight = ( isFlash: boolean, resized = false, ) => { - const lineCounts = getConfig(config.html5LineCounts, isFlash), - commentStageSize = getConfig(config.commentStageSize, isFlash), - lineHeight = commentStageSize.height / lineCounts.doubleResized[fontSize], - defaultLineCount = lineCounts.default[fontSize]; + const lineCounts = getConfig(config.html5LineCounts, isFlash); + const commentStageSize = getConfig(config.commentStageSize, isFlash); + const lineHeight = + commentStageSize.height / lineCounts.doubleResized[fontSize]; + const defaultLineCount = lineCounts.default[fontSize]; if (resized) { const resizedLineCount = lineCounts.resized[fontSize]; return ( @@ -45,8 +46,8 @@ const getLineHeight = ( * @returns フォントサイズ */ const getCharSize = (fontSize: CommentSize, isFlash: boolean): number => { - const lineCounts = getConfig(config.html5LineCounts, isFlash), - commentStageSize = getConfig(config.commentStageSize, isFlash); + const lineCounts = getConfig(config.html5LineCounts, isFlash); + const commentStageSize = getConfig(config.commentStageSize, isFlash); return commentStageSize.height / lineCounts.doubleResized[fontSize]; }; @@ -67,10 +68,10 @@ const measure = (comment: MeasureInput, renderer: IRenderer) => { const addHTML5PartToResult = ( lineContent: CommentContentItem[], part: string, - font?: CommentHTML5Font, + _font?: CommentHTML5Font, ) => { if (part === "") return; - font ??= "defont"; + const font = _font ?? "defont"; for (const key of Object.keys(config.compatSpacer.html5)) { const spacerWidth = config.compatSpacer.html5[key]?.[font]; if (!spacerWidth) continue; @@ -105,9 +106,9 @@ const addHTML5PartToResult = ( * @returns 計測結果 */ const measureWidth = (comment: MeasureInput, renderer: IRenderer) => { - const { fontSize, scale } = getFontSizeAndScale(comment.charSize), - lineWidth: number[] = [], - itemWidth: number[][] = []; + const { fontSize, scale } = getFontSizeAndScale(comment.charSize); + const lineWidth: number[] = []; + const itemWidth: number[][] = []; renderer.setFont(parseFont(comment.font, fontSize)); let currentWidth = 0; for (const item of comment.content) { @@ -143,10 +144,11 @@ const measureWidth = (comment: MeasureInput, renderer: IRenderer) => { /** * フォントサイズとスケールを返す - * @param charSize 文字サイズ + * @param _charSize 文字サイズ * @returns フォントサイズとスケール */ -const getFontSizeAndScale = (charSize: number) => { +const getFontSizeAndScale = (_charSize: number) => { + let charSize = _charSize; charSize *= 0.8; if (charSize < config.html5MinFontSize) { if (charSize >= 1) charSize = Math.floor(charSize); diff --git a/src/utils/sort.ts b/src/utils/sort.ts index d7225355..074c6189 100755 --- a/src/utils/sort.ts +++ b/src/utils/sort.ts @@ -7,11 +7,11 @@ const nativeSort = (getter: (input: T) => number) => { return (a: T, b: T) => { if (getter(a) > getter(b)) { return 1; - } else if (getter(a) < getter(b)) { + } + if (getter(a) < getter(b)) { return -1; - } else { - return 0; } + return 0; }; };