diff --git a/src/inputParser.ts b/src/inputParser.ts index 808578b7..1d972607 100644 --- a/src/inputParser.ts +++ b/src/inputParser.ts @@ -140,18 +140,20 @@ const fromLegacy = (data: rawApiResponse[]): formattedComment[] => { * @return {formattedComment[]} */ const fromLegacyOwner = (data: string): formattedComment[] => { - let data_: formattedComment[] = [], + const data_: formattedComment[] = [], comments = data.split("\n"); for (let i = 0; i < comments.length; i++) { - let commentData = comments[i]!.split(":"); + const value = comments[i]; + if (!value) continue; + const commentData = value.split(":"); if (commentData.length < 3) { continue; } else if (commentData.length > 3) { for (let j = 3; j < commentData.length; j++) { - commentData[2] += ":" + commentData[j]; + commentData[2] += `:${commentData[j]}`; } } - let tmpParam: formattedComment = { + const tmpParam: formattedComment = { id: i, vpos: Number(commentData[0]), content: commentData[2] || "", diff --git a/src/main.ts b/src/main.ts index ed292914..cb3bd8bd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -405,8 +405,8 @@ class NiconiComments { width_arr.push(measure.width); } const width = width_arr.reduce((p, c) => p + c, 0) / width_arr.length; - let width_max = Math.max(...width_arr), - width_min = Math.min(...width_arr), + let width_max = Math.max(...width_arr); + const width_min = Math.min(...width_arr), height = comment.fontSize * comment.lineHeight * @@ -893,7 +893,7 @@ class NiconiComments { * @param vpos - 動画の現在位置の100倍 ニコニコから吐き出されるコメントの位置情報は主にこれ * @param forceRendering */ - drawCanvas(vpos: number, forceRendering: boolean = false) { + drawCanvas(vpos: number, forceRendering = false) { const drawCanvasStart = performance.now(); if (this.lastVpos === vpos && !forceRendering) return; this.lastVpos = vpos; diff --git a/src/typeGuard.ts b/src/typeGuard.ts index 91e2ab3e..a736eaf6 100644 --- a/src/typeGuard.ts +++ b/src/typeGuard.ts @@ -214,7 +214,7 @@ const typeGuard = { config: { initOptions: (item: unknown): item is InitOptions => { if (typeof item !== "object" || !item) return false; - const keys: { [key: string]: Function } = { + const keys: { [key: string]: (i: unknown) => boolean } = { useLegacy: isBoolean, formatted: isBoolean, showCollision: isBoolean, @@ -227,16 +227,19 @@ const typeGuard = { config: typeGuard.config.config, format: (i: unknown) => typeof i === "string" && - i.match( + !!i.match( /^(niconicome|formatted|legacy|legacyOwner|owner|v1|default)$/ ), video: (i: unknown) => typeof i === "object" && (i as HTMLVideoElement).nodeName === "VIDEO", }; for (const key in keys) { + console.log(keys[key]); if ( (item as { [key: string]: unknown })[key] !== undefined && - !(keys[key] as Function)((item as { [key: string]: unknown })[key]) + !(keys[key] as (i: unknown) => boolean)( + (item as { [key: string]: unknown })[key] + ) ) { console.warn( `[Incorrect input] var: initOptions, key: ${key}, value: ${ @@ -288,7 +291,7 @@ const typeGuard = { ) === 0 ); }; - const keys: { [key: string]: Function } = { + const keys: { [key: string]: (i: unknown) => boolean } = { commentYPaddingTop: isNumber, commentYMarginBottom: isNumber, fpsInterval: isNumber, @@ -301,6 +304,11 @@ const typeGuard = { sameCARange: isNumber, sameCAGap: isNumber, sameCAMinScore: isNumber, + contextStrokeOpacity: isNumber, + contextFillLiveOpacity: isNumber, + contextLineWidth: isNumber, + contextStrokeColor: isString, + contextStrokeInversionColor: isString, colors: (i: unknown) => typeof i === "object" && Object.keys(i as { [key: string]: unknown }).reduce( @@ -325,9 +333,12 @@ const typeGuard = { ) === 0, }; for (const key in item) { + console.log(key, item, keys); if ( (item as { [key: string]: unknown })[key] !== undefined && - !(keys[key] as Function)((item as { [key: string]: unknown })[key]) + !(keys[key] as (i: unknown) => boolean)( + (item as { [key: string]: unknown })[key] + ) ) { console.warn( `[Incorrect input] var: initOptions, key: ${key}, value: ${ @@ -348,6 +359,7 @@ const typeGuard = { }; const isBoolean = (i: unknown): i is boolean => typeof i === "boolean"; const isNumber = (i: unknown): i is number => typeof i === "number"; +const isString = (i: unknown): i is string => typeof i === "string"; const isStringKeyObject = (i: unknown): i is { [key: string]: unknown } => typeof i === "object";