diff --git a/index.js b/index.js index f247e02..bb63b08 100644 --- a/index.js +++ b/index.js @@ -161,12 +161,17 @@ async function LOADCOMMENT(mode) { continue; } if (res?.meta?.errorCode === "INVALID_TOKEN") { - logger("旧コメントAPIに切り替えています..."); + logger("ログインしていません。"); + alert( + "【コメント増量】ログアウト状態です。ログインをして再度実行してください。" + ); + document.getElementById("loading").style.display = "none"; + document.getElementById("allcommentsetting").style.display = "none"; isLoggedIn = false; j--; totalThreadCount /= 3; - await prepareLegacy(); - continue; + //await prepareLegacy(); + //continue; } (thread.fork === "owner" ? ownerComments : comments).push( ...res.data.threads[0].comments diff --git a/lib/niconicomments.js b/lib/niconicomments.js index 1671ae2..5f88e96 100644 --- a/lib/niconicomments.js +++ b/lib/niconicomments.js @@ -4,10 +4,15 @@ Released under the MIT License. */ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.NiconiComments = factory()); -})(this, (function () { 'use strict'; + typeof exports === "object" && typeof module !== "undefined" + ? (module.exports = factory()) + : typeof define === "function" && define.amd + ? define(factory) + : ((global = + typeof globalThis !== "undefined" ? globalThis : global || self), + (global.NiconiComments = factory())); +})(this, function () { + "use strict"; let imageCache = {}; const resetImageCache = () => { @@ -38,14 +43,20 @@ plugins = input; }; - var index$3 = /*#__PURE__*/Object.freeze({ + var index$3 = /*#__PURE__*/ Object.freeze({ __proto__: null, - get imageCache () { return imageCache; }, - get nicoScripts () { return nicoScripts; }, - get plugins () { return plugins; }, + get imageCache() { + return imageCache; + }, + get nicoScripts() { + return nicoScripts; + }, + get plugins() { + return plugins; + }, resetImageCache: resetImageCache, resetNicoScripts: resetNicoScripts, - setPlugins: setPlugins + setPlugins: setPlugins, }); let defaultConfig; @@ -76,15 +87,21 @@ options = value; }; - var config$1 = /*#__PURE__*/Object.freeze({ + var config$1 = /*#__PURE__*/ Object.freeze({ __proto__: null, - get config () { return config; }, - get defaultConfig () { return defaultConfig; }, + get config() { + return config; + }, + get defaultConfig() { + return defaultConfig; + }, defaultOptions: defaultOptions, - get options () { return options; }, + get options() { + return options; + }, setConfig: setConfig, setOptions: setOptions, - updateConfig: updateConfig + updateConfig: updateConfig, }); class CanvasRenderingContext2DError extends Error { @@ -92,7 +109,8 @@ super("CanvasRenderingContext2DError", options); } } - CanvasRenderingContext2DError.prototype.name = "CanvasRenderingContext2DError"; + CanvasRenderingContext2DError.prototype.name = + "CanvasRenderingContext2DError"; class InvalidFormatError extends Error { constructor(options = {}) { @@ -103,7 +121,10 @@ class InvalidOptionError extends Error { constructor(options = {}) { - super("Invalid option\nPlease check document: https://xpadev-net.github.io/niconicomments/#p_options", options); + super( + "Invalid option\nPlease check document: https://xpadev-net.github.io/niconicomments/#p_options", + options + ); } } InvalidOptionError.prototype.name = "InvalidOptionError"; @@ -119,12 +140,12 @@ } NotImplementedError.prototype.name = "NotImplementedError"; - var index$2 = /*#__PURE__*/Object.freeze({ + var index$2 = /*#__PURE__*/ Object.freeze({ __proto__: null, CanvasRenderingContext2DError: CanvasRenderingContext2DError, InvalidFormatError: InvalidFormatError, InvalidOptionError: InvalidOptionError, - NotImplementedError: NotImplementedError + NotImplementedError: NotImplementedError, }); const ArrayPush = (array, key, push) => { @@ -137,18 +158,15 @@ array[Number(key)]?.push(push); }; const ArrayEqual = (a, b) => { - if (a.length !== b.length) - return false; + if (a.length !== b.length) return false; for (let i = 0, n = a.length; i < n; ++i) { - if (a[i] !== b[i]) - return false; + if (a[i] !== b[i]) return false; } return true; }; const hex2rgb = (hex) => { - if (hex.slice(0, 1) === "#") - hex = hex.slice(1); + if (hex.slice(0, 1) === "#") hex = hex.slice(1); if (hex.length === 3) hex = hex.slice(0, 1) + @@ -157,13 +175,14 @@ hex.slice(1, 2) + 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 [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map(function ( + str + ) { return parseInt(str, 16); }); }; const hex2rgba = (hex) => { - if (hex.slice(0, 1) === "#") - hex = hex.slice(1); + if (hex.slice(0, 1) === "#") hex = hex.slice(1); if (hex.length === 4) hex = hex.slice(0, 1) + @@ -180,8 +199,7 @@ hex.slice(4, 6), hex.slice(4, 6), ].map((str, index) => { - if (index === 3) - return parseInt(str, 16) / 256; + if (index === 3) return parseInt(str, 16) / 256; return parseInt(str, 16); }); }; @@ -190,15 +208,18 @@ const color = comment.strokeColor.slice(1); const length = color.length; if (length === 3 || length === 6) { - return `rgba(${hex2rgb(color).join(",")},${config.contextStrokeOpacity})`; - } - else if (length === 4 || length === 8) { + return `rgba(${hex2rgb(color).join(",")},${ + config.contextStrokeOpacity + })`; + } else if (length === 4 || length === 8) { return `rgba(${hex2rgba(color).join(",")})`; } } - return `rgba(${hex2rgb(comment.color === "#000000" - ? config.contextStrokeInversionColor - : config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`; + return `rgba(${hex2rgb( + comment.color === "#000000" + ? config.contextStrokeInversionColor + : config.contextStrokeColor + ).join(",")},${config.contextStrokeOpacity})`; }; const colors = { @@ -231,9 +252,9 @@ black2: "#666666", }; - var colors$1 = /*#__PURE__*/Object.freeze({ + var colors$1 = /*#__PURE__*/ Object.freeze({ __proto__: null, - colors: colors + colors: colors, }); const isBoolean = (i) => typeof i === "boolean"; @@ -241,97 +262,94 @@ const isObject = (i) => typeof i === "object"; const typeGuard = { formatted: { - comment: (i) => objectVerify(i, [ - "id", - "vpos", - "content", - "date", - "date_usec", - "owner", - "premium", - "mail", - "user_id", - "layer", - ]), + comment: (i) => + objectVerify(i, [ + "id", + "vpos", + "content", + "date", + "date_usec", + "owner", + "premium", + "mail", + "user_id", + "layer", + ]), comments: (i) => { - if (typeof i !== "object") - return false; + if (typeof i !== "object") return false; for (const item of i) { - if (!typeGuard.formatted.comment(item)) - return false; + if (!typeGuard.formatted.comment(item)) return false; } return true; }, - legacyComment: (i) => objectVerify(i, [ - "id", - "vpos", - "content", - "date", - "owner", - "premium", - "mail", - ]), + legacyComment: (i) => + objectVerify(i, [ + "id", + "vpos", + "content", + "date", + "owner", + "premium", + "mail", + ]), legacyComments: (i) => { - if (typeof i !== "object") - return false; + if (typeof i !== "object") return false; for (const item of i) { - if (!typeGuard.formatted.legacyComment(item)) - return false; + if (!typeGuard.formatted.legacyComment(item)) return false; } return true; }, }, legacy: { rawApiResponses: (i) => { - if (typeof i !== "object") - return false; + if (typeof i !== "object") return false; for (const itemWrapper of i) { for (const key of Object.keys(itemWrapper)) { const item = itemWrapper[key]; - if (!item) - continue; - if (!(typeGuard.legacy.apiChat(item) || - typeGuard.legacy.apiGlobalNumRes(item) || - typeGuard.legacy.apiLeaf(item) || - typeGuard.legacy.apiPing(item) || - typeGuard.legacy.apiThread(item))) { + if (!item) continue; + if ( + !( + typeGuard.legacy.apiChat(item) || + typeGuard.legacy.apiGlobalNumRes(item) || + typeGuard.legacy.apiLeaf(item) || + typeGuard.legacy.apiPing(item) || + typeGuard.legacy.apiThread(item) + ) + ) { return false; } } } return true; }, - apiChat: (i) => typeof i === "object" && + apiChat: (i) => + typeof i === "object" && objectVerify(i, ["content", "date", "no", "thread", "vpos"]), apiGlobalNumRes: (i) => objectVerify(i, ["num_res", "thread"]), apiLeaf: (i) => objectVerify(i, ["count", "thread"]), apiPing: (i) => objectVerify(i, ["content"]), - apiThread: (i) => objectVerify(i, [ - "resultcode", - "revision", - "server_time", - "thread", - "ticket", - ]), + apiThread: (i) => + objectVerify(i, [ + "resultcode", + "revision", + "server_time", + "thread", + "ticket", + ]), }, xmlDocument: (i) => { - if (!i.documentElement || - i.documentElement.nodeName !== "packet") - return false; - if (!i.documentElement.children) + if (!i.documentElement || i.documentElement.nodeName !== "packet") return false; + if (!i.documentElement.children) return false; for (const element of Array.from(i.documentElement.children)) { - if (!element || element.nodeName !== "chat") - continue; - if (!typeAttributeVerify(element, ["vpos", "date"])) - return false; + if (!element || element.nodeName !== "chat") continue; + if (!typeAttributeVerify(element, ["vpos", "date"])) return false; } return true; }, legacyOwner: { comments: (i) => { - if (typeof i !== "string") - return false; + if (typeof i !== "string") return false; const lists = i.split("\n"); for (const list of lists) { if (list.split(":").length < 3) { @@ -344,78 +362,84 @@ owner: { comment: (i) => objectVerify(i, ["time", "command", "comment"]), comments: (i) => { - if (typeof i !== "object") - return false; + if (typeof i !== "object") return false; for (const item of i) { - if (!typeGuard.owner.comment(item)) - return false; + if (!typeGuard.owner.comment(item)) return false; } return true; }, }, v1: { - comment: (i) => objectVerify(i, [ - "id", - "no", - "vposMs", - "body", - "commands", - "userId", - "isPremium", - "score", - "postedAt", - "nicoruCount", - "nicoruId", - "source", - "isMyPost", - ]), + comment: (i) => + objectVerify(i, [ + "id", + "no", + "vposMs", + "body", + "commands", + "userId", + "isPremium", + "score", + "postedAt", + "nicoruCount", + "nicoruId", + "source", + "isMyPost", + ]), thread: (i) => { if (!objectVerify(i, ["id", "fork", "commentCount", "comments"])) return false; for (const value of i.comments) { - if (!typeGuard.v1.comment(value)) - return false; + if (!typeGuard.v1.comment(value)) return false; } return true; }, threads: (i) => { - if (typeof i !== "object") - return false; + if (typeof i !== "object") return false; for (const item of i) { - if (!typeGuard.v1.thread(item)) - return false; + if (!typeGuard.v1.thread(item)) return false; } return true; }, }, nicoScript: { range: { - target: (i) => typeof i === "string" && !!i.match(/^(?:\u6295?\u30b3\u30e1|\u5168)$/), + target: (i) => + typeof i === "string" && + !!i.match(/^(?:\u6295?\u30b3\u30e1|\u5168)$/), }, replace: { range: (i) => typeof i === "string" && !!i.match(/^[\u5358\u5168]$/), - target: (i) => typeof i === "string" && - !!i.match(/^(?:\u30b3\u30e1|\u6295\u30b3\u30e1|\u5168|\u542b\u3080|\u542b\u307e\u306a\u3044)$/), - condition: (i) => typeof i === "string" && + target: (i) => + typeof i === "string" && + !!i.match( + /^(?:\u30b3\u30e1|\u6295\u30b3\u30e1|\u5168|\u542b\u3080|\u542b\u307e\u306a\u3044)$/ + ), + condition: (i) => + typeof i === "string" && !!i.match(/^(?:\u90e8\u5206\u4e00\u81f4|\u5b8c\u5168\u4e00\u81f4)$/), }, }, comment: { - font: (i) => typeof i === "string" && !!i.match(/^(?:gothic|mincho|defont)$/), + font: (i) => + typeof i === "string" && !!i.match(/^(?:gothic|mincho|defont)$/), loc: (i) => typeof i === "string" && !!i.match(/^(?:ue|naka|shita)$/), size: (i) => typeof i === "string" && !!i.match(/^(?:big|medium|small)$/), command: { - key: (i) => typeof i === "string" && !!i.match(/^(?:full|ender|_live|invisible)$/), + key: (i) => + typeof i === "string" && + !!i.match(/^(?:full|ender|_live|invisible)$/), }, color: (i) => typeof i === "string" && Object.keys(colors).includes(i), - colorCode: (i) => typeof i === "string" && !!i.match(/^#(?:[0-9a-z]{3}|[0-9a-z]{6})$/), - colorCodeAllowAlpha: (i) => typeof i === "string" && + colorCode: (i) => + typeof i === "string" && !!i.match(/^#(?:[0-9a-z]{3}|[0-9a-z]{6})$/), + colorCodeAllowAlpha: (i) => + typeof i === "string" && !!i.match(/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/), }, config: { initOptions: (item) => { - if (typeof item !== "object" || !item) - return false; + if (typeof item !== "object" || !item) return false; const keys = { useLegacy: isBoolean, formatted: isBoolean, @@ -428,14 +452,18 @@ keepCA: isBoolean, scale: isNumber, config: isObject, - format: (i) => typeof i === "string" && - !!i.match(/^(XMLDocument|niconicome|formatted|legacy|legacyOwner|owner|v1|default|empty)$/), + format: (i) => + typeof i === "string" && + !!i.match( + /^(XMLDocument|niconicome|formatted|legacy|legacyOwner|owner|v1|default|empty)$/ + ), video: (i) => typeof i === "object" && i.nodeName === "VIDEO", }; for (const key of Object.keys(keys)) { - if (item[key] !== undefined && - !keys[key](item[key])) { - console.warn(`[Incorrect input] var: initOptions, key: ${key}, value: ${item[key]}`); + if (item[key] !== undefined && !keys[key](item[key])) { + console.warn( + `[Incorrect input] var: initOptions, key: ${key}, value: ${item[key]}` + ); return false; } } @@ -443,42 +471,42 @@ }, }, internal: { - CommentMeasuredContentItem: (i) => objectVerify(i, ["content", "slicedContent", "width"]), - CommentMeasuredContentItemArray: (i) => Array.isArray(i) && + CommentMeasuredContentItem: (i) => + objectVerify(i, ["content", "slicedContent", "width"]), + CommentMeasuredContentItemArray: (i) => + Array.isArray(i) && i.every(typeGuard.internal.CommentMeasuredContentItem), - MultiConfigItem: (i) => typeof i === "object" && objectVerify(i, ["html5", "flash"]), + MultiConfigItem: (i) => + typeof i === "object" && objectVerify(i, ["html5", "flash"]), HTML5Fonts: (i) => i === "defont" || i === "mincho" || i === "gothic", - MeasureInput: (i) => objectVerify(i, [ - "font", - "content", - "lineHeight", - "charSize", - "lineCount", - ]), + MeasureInput: (i) => + objectVerify(i, [ + "font", + "content", + "lineHeight", + "charSize", + "lineCount", + ]), }, }; const objectVerify = (item, keys) => { - if (typeof item !== "object" || !item) - return false; + if (typeof item !== "object" || !item) return false; for (const key of keys) { - if (!Object.prototype.hasOwnProperty.call(item, key)) - return false; + if (!Object.prototype.hasOwnProperty.call(item, key)) return false; } return true; }; const typeAttributeVerify = (item, keys) => { - if (typeof item !== "object" || !item) - return false; + if (typeof item !== "object" || !item) return false; for (const key of keys) { - if (item.getAttribute(key) === null) - return false; + if (item.getAttribute(key) === null) return false; } return true; }; - var typeGuard$1 = /*#__PURE__*/Object.freeze({ + var typeGuard$1 = /*#__PURE__*/ Object.freeze({ __proto__: null, - default: typeGuard + default: typeGuard, }); const getConfig = (input, isFlash = false) => { @@ -489,13 +517,20 @@ }; const isLineBreakResize = (comment) => { - return (!comment.resized && + return ( + !comment.resized && !comment.ender && - comment.lineCount >= config.lineBreakCount[comment.size]); + comment.lineCount >= config.lineBreakCount[comment.size] + ); }; const getDefaultCommand = (vpos) => { - nicoScripts.default = nicoScripts.default.filter((item) => !item.long || item.start + item.long >= vpos); - let color = undefined, size = undefined, font = undefined, loc = undefined; + nicoScripts.default = nicoScripts.default.filter( + (item) => !item.long || item.start + item.long >= vpos + ); + let color = undefined, + size = undefined, + font = undefined, + loc = undefined; for (const item of nicoScripts.default) { if (item.loc) { loc = item.loc; @@ -509,13 +544,13 @@ if (item.font) { font = item.font; } - if (loc && color && size && font) - break; + if (loc && color && size && font) break; } return { color, size, font, loc }; }; - const nicoscriptReplaceIgnoreable = (comment, item) => ((item.target === "\u30b3\u30e1" || - item.target === "\u542b\u307e\u306a\u3044") && + const nicoscriptReplaceIgnoreable = (comment, item) => + ((item.target === "\u30b3\u30e1" || + item.target === "\u542b\u307e\u306a\u3044") && comment.owner) || (item.target === "\u6295\u30b3\u30e1" && !comment.owner) || (item.target === "\u542b\u307e\u306a\u3044" && comment.owner) || @@ -524,14 +559,17 @@ (item.condition === "\u90e8\u5206\u4e00\u81f4" && comment.content.indexOf(item.keyword) === -1); const applyNicoScriptReplace = (comment, commands) => { - nicoScripts.replace = nicoScripts.replace.filter((item) => !item.long || item.start + item.long >= comment.vpos); + nicoScripts.replace = nicoScripts.replace.filter( + (item) => !item.long || item.start + item.long >= comment.vpos + ); for (const item of nicoScripts.replace) { - if (nicoscriptReplaceIgnoreable(comment, item)) - continue; + if (nicoscriptReplaceIgnoreable(comment, item)) continue; if (item.range === "\u5358") { - comment.content = comment.content.replaceAll(item.keyword, item.replace); - } - else { + comment.content = comment.content.replaceAll( + item.keyword, + item.replace + ); + } else { comment.content = item.replace; } item.loc && (commands.loc = item.loc); @@ -565,29 +603,28 @@ }; }; const parseBrackets = (input) => { - const content = input.split(""), result = []; - let quote = "", last_i = "", string = ""; + const content = input.split(""), + result = []; + let quote = "", + last_i = "", + string = ""; for (const i of content) { if (i.match(/["'\u300c]/) && quote === "") { quote = i; - } - else if (i.match(/["']/) && quote === i && last_i !== "\\") { + } else if (i.match(/["']/) && quote === i && last_i !== "\\") { result.push(string.replaceAll("\\n", "\n")); quote = ""; string = ""; - } - else if (i.match(/\u300d/) && quote === "\u300c") { + } else if (i.match(/\u300d/) && quote === "\u300c") { result.push(string); quote = ""; string = ""; - } - else if (quote === "" && i.match(/\s+/)) { + } else if (quote === "" && i.match(/\s+/)) { if (string) { result.push(string); string = ""; } - } - else { + } else { string += i; } last_i = i; @@ -597,17 +634,22 @@ }; const addNicoscriptReplace = (comment, commands) => { const result = parseBrackets(comment.content.slice(4)); - if (result[0] === undefined || + if ( + result[0] === undefined || (result[2] !== undefined && !typeGuard.nicoScript.replace.range(result[2])) || (result[3] !== undefined && !typeGuard.nicoScript.replace.target(result[3])) || (result[4] !== undefined && - !typeGuard.nicoScript.replace.condition(result[4]))) + !typeGuard.nicoScript.replace.condition(result[4])) + ) return; nicoScripts.replace.unshift({ start: comment.vpos, - long: commands.long === undefined ? undefined : Math.floor(commands.long * 100), + long: + commands.long === undefined + ? undefined + : Math.floor(commands.long * 100), keyword: result[0], replace: result[1] || "", range: result[2] || "\u5358", @@ -623,27 +665,23 @@ }; const sortNicoscriptReplace = () => { nicoScripts.replace.sort((a, b) => { - if (a.start < b.start) - return -1; - if (a.start > b.start) - return 1; - if (a.no < b.no) - return -1; - if (a.no > b.no) - return 1; + if (a.start < b.start) return -1; + if (a.start > b.start) return 1; + if (a.no < b.no) return -1; + if (a.no > b.no) return 1; return 0; }); }; const processNicoscript = (comment, commands) => { - const nicoscript = comment.content.match(/^[@\uff20](\u30c7\u30d5\u30a9\u30eb\u30c8|\u7f6e\u63db|\u9006|\u30b3\u30e1\u30f3\u30c8\u7981\u6b62|\u30b7\u30fc\u30af\u7981\u6b62|\u30b8\u30e3\u30f3\u30d7|\u30dc\u30bf\u30f3)(?:\s(.+))?/); - if (!nicoscript) - return; + const nicoscript = comment.content.match( + /^[@\uff20](\u30c7\u30d5\u30a9\u30eb\u30c8|\u7f6e\u63db|\u9006|\u30b3\u30e1\u30f3\u30c8\u7981\u6b62|\u30b7\u30fc\u30af\u7981\u6b62|\u30b8\u30e3\u30f3\u30d7|\u30dc\u30bf\u30f3)(?:\s(.+))?/ + ); + if (!nicoscript) return; if (nicoscript[1] === "\u30dc\u30bf\u30f3" && nicoscript[2]) { processAtButton(commands); return; } - if (!comment.owner) - return; + if (!comment.owner) return; commands.invisible = true; if (nicoscript[1] === "\u30c7\u30d5\u30a9\u30eb\u30c8") { processDefaultScript(comment, commands); @@ -672,7 +710,10 @@ const processDefaultScript = (comment, commands) => { nicoScripts.default.unshift({ start: comment.vpos, - long: commands.long === undefined ? undefined : Math.floor(commands.long * 100), + long: + commands.long === undefined + ? undefined + : Math.floor(commands.long * 100), color: commands.color, size: commands.size, font: commands.font, @@ -680,8 +721,14 @@ }); }; const processReverseScript = (comment, commands) => { - const reverse = comment.content.match(/^[@\uff20]\u9006(?:\s+)?(\u5168|\u30b3\u30e1|\u6295\u30b3\u30e1)?/); - if (!reverse || !reverse[1] || !typeGuard.nicoScript.range.target(reverse[1])) + const reverse = comment.content.match( + /^[@\uff20]\u9006(?:\s+)?(\u5168|\u30b3\u30e1|\u6295\u30b3\u30e1)?/ + ); + if ( + !reverse || + !reverse[1] || + !typeGuard.nicoScript.range.target(reverse[1]) + ) return; if (commands.long === undefined) { commands.long = 30; @@ -711,9 +758,10 @@ }); }; const processJumpScript$1 = (comment, commands, input) => { - const options = input.match(/\s*((?:sm|so|nm|\uff53\uff4d|\uff53\uff4f|\uff4e\uff4d)?[1-9\uff11-\uff19][0-9\uff11-\uff19]*|#[0-9]+:[0-9]+(?:\.[0-9]+)?)\s+(.*)/); - if (!options || !options[1]) - return; + const options = input.match( + /\s*((?:sm|so|nm|\uff53\uff4d|\uff53\uff4f|\uff4e\uff4d)?[1-9\uff11-\uff19][0-9\uff11-\uff19]*|#[0-9]+:[0-9]+(?:\.[0-9]+)?)\s+(.*)/ + ); + if (!options || !options[1]) return; nicoScripts.jump.unshift({ start: comment.vpos, end: commands.long === undefined ? undefined : commands.long * 100, @@ -726,7 +774,8 @@ commands.button = true; }; const parseCommands = (comment) => { - const commands = comment.mail, isFlash = isFlashComment(comment); + const commands = comment.mail, + isFlash = isFlashComment(comment); const result = { loc: undefined, size: undefined, @@ -799,28 +848,31 @@ } }; const getColor = (match) => { - if (!match) - return; + if (!match) return; const value = match[1]; if (typeGuard.comment.color(value)) { return colors[value]; - } - else if (typeGuard.comment.colorCodeAllowAlpha(value)) { + } else if (typeGuard.comment.colorCodeAllowAlpha(value)) { return value; } return; }; - const isFlashComment = (comment) => options.mode === "flash" || + const isFlashComment = (comment) => + options.mode === "flash" || (options.mode === "default" && - !(comment.mail.includes("gothic") || + !( + comment.mail.includes("gothic") || comment.mail.includes("defont") || - comment.mail.includes("mincho")) && + comment.mail.includes("mincho") + ) && (comment.date < config.flashThreshold || comment.mail.includes("nico:flash"))); const isReverseActive = (vpos, isOwner) => { for (const range of nicoScripts.reverse) { - if ((range.target === "コメ" && isOwner) || - (range.target === "投コメ" && !isOwner)) + if ( + (range.target === "コメ" && isOwner) || + (range.target === "投コメ" && !isOwner) + ) continue; if (range.start < vpos && vpos < range.end) { return true; @@ -830,13 +882,14 @@ }; const isBanActive = (vpos) => { for (const range of nicoScripts.ban) { - if (range.start < vpos && vpos < range.end) - return true; + if (range.start < vpos && vpos < range.end) return true; } return false; }; const processFixedComment = (comment, collision, timeline) => { - let posY = 0, isChanged = true, count = 0; + let posY = 0, + isChanged = true, + count = 0; while (isChanged && count < 10) { isChanged = false; count++; @@ -844,27 +897,27 @@ const result = getPosY(posY, comment, collision[comment.vpos + j]); posY = result.currentPos; isChanged = result.isChanged; - if (result.isBreak) - break; + if (result.isBreak) break; } } for (let j = 0; j < comment.long; j++) { const vpos = comment.vpos + j; ArrayPush(timeline, vpos, comment); - if (j > comment.long - 20) - continue; + if (j > comment.long - 20) continue; ArrayPush(collision, vpos, comment); } comment.posY = posY; }; const processMovableComment = (comment, collision, timeline) => { - const beforeVpos = Math.round(-288 / ((1632 + comment.width) / (comment.long + 125))) - 100; + const beforeVpos = + Math.round(-288 / ((1632 + comment.width) / (comment.long + 125))) - 100; const posY = (() => { if (config.canvasHeight < comment.height) { return (comment.height - config.canvasHeight) / -2; } let posY = 0; - let isChanged = true, count = 0; + let isChanged = true, + count = 0; while (isChanged && count < 10) { isChanged = false; count++; @@ -872,22 +925,25 @@ const vpos = comment.vpos + j; const left_pos = getPosX(comment.comment, vpos); let isBreak = false; - if (left_pos + comment.width >= config.collisionRange.right && - left_pos <= config.collisionRange.right) { + if ( + left_pos + comment.width >= config.collisionRange.right && + left_pos <= config.collisionRange.right + ) { const result = getPosY(posY, comment, collision.right[vpos]); posY = result.currentPos; isChanged = result.isChanged; isBreak = result.isBreak; } - if (left_pos + comment.width >= config.collisionRange.left && - left_pos <= config.collisionRange.left) { + if ( + left_pos + comment.width >= config.collisionRange.left && + left_pos <= config.collisionRange.left + ) { const result = getPosY(posY, comment, collision.left[vpos]); posY = result.currentPos; isChanged = result.isChanged; isBreak = result.isBreak; } - if (isBreak) - return posY; + if (isBreak) return posY; } } return posY; @@ -896,26 +952,32 @@ const vpos = comment.vpos + j; const left_pos = getPosX(comment.comment, vpos); ArrayPush(timeline, vpos, comment); - if (left_pos + comment.width >= config.collisionRange.right && - left_pos <= config.collisionRange.right) { + if ( + left_pos + comment.width >= config.collisionRange.right && + left_pos <= config.collisionRange.right + ) { ArrayPush(collision.right, vpos, comment); } - if (left_pos + comment.width >= config.collisionRange.left && - left_pos <= config.collisionRange.left) { + if ( + left_pos + comment.width >= config.collisionRange.left && + left_pos <= config.collisionRange.left + ) { ArrayPush(collision.left, vpos, comment); } } comment.posY = posY; }; const getPosY = (currentPos, targetComment, collision) => { - let isChanged = false, isBreak = false; - if (!collision) - return { currentPos, isChanged, isBreak }; + let isChanged = false, + isBreak = false; + if (!collision) return { currentPos, isChanged, isBreak }; for (const collisionItem of collision) { - if (currentPos < collisionItem.posY + collisionItem.height && + if ( + currentPos < collisionItem.posY + collisionItem.height && currentPos + targetComment.height > collisionItem.posY && collisionItem.owner === targetComment.owner && - collisionItem.layer === targetComment.layer) { + collisionItem.layer === targetComment.layer + ) { if (collisionItem.posY + collisionItem.height > currentPos) { currentPos = collisionItem.posY + collisionItem.height; isChanged = true; @@ -924,13 +986,13 @@ if (config.canvasHeight < targetComment.height) { if (targetComment.mail.includes("naka")) { currentPos = (targetComment.height - config.canvasHeight) / -2; - } - else { + } else { currentPos = 0; } - } - else { - currentPos = Math.floor(Math.random() * (config.canvasHeight - targetComment.height)); + } else { + currentPos = Math.floor( + Math.random() * (config.canvasHeight - targetComment.height) + ); } isBreak = true; break; @@ -943,10 +1005,13 @@ if (comment.loc !== "naka") { return (config.canvasWidth - comment.width) / 2; } - const speed = (config.commentDrawRange + comment.width * config.nakaCommentSpeedOffset) / + const speed = + (config.commentDrawRange + + comment.width * config.nakaCommentSpeedOffset) / (comment.long + 100); const vposLapsed = vpos - comment.vpos; - const posX = config.commentDrawPadding + + const posX = + config.commentDrawPadding + config.commentDrawRange - (vposLapsed + 100) * speed; if (isReverse) { @@ -970,23 +1035,29 @@ const changeCALayer = (rawData) => { const userScoreList = getUsersScore(rawData); const filteredComments = removeDuplicateCommentArt(rawData); - const commentArts = filteredComments.filter((comment) => (userScoreList[comment.user_id] || 0) >= config.sameCAMinScore && - !comment.owner); + const commentArts = filteredComments.filter( + (comment) => + (userScoreList[comment.user_id] || 0) >= config.sameCAMinScore && + !comment.owner + ); const commentArtsGroupedByUser = groupCommentsByUser(commentArts); - const commentArtsGroupedByTimes = groupCommentsByTime(commentArtsGroupedByUser); + const commentArtsGroupedByTimes = groupCommentsByTime( + commentArtsGroupedByUser + ); updateLayerId(commentArtsGroupedByTimes); return filteredComments; }; const getUsersScore = (comments) => { const userScoreList = {}; for (const comment of comments) { - if (comment.user_id === undefined || comment.user_id === -1) - continue; + if (comment.user_id === undefined || comment.user_id === -1) continue; userScoreList[comment.user_id] ||= 0; - if (comment.mail.includes("ca") || + if ( + comment.mail.includes("ca") || comment.mail.includes("patissier") || comment.mail.includes("ender") || - comment.mail.includes("full")) { + comment.mail.includes("full") + ) { userScoreList[comment.user_id] += 5; } const lineCount = (comment.content.match(/\r\n|\n|\r/g) || []).length; @@ -1000,15 +1071,18 @@ const index = {}; return comments.filter((comment) => { const key = `${comment.content}@@${[...comment.mail] - .sort() - .filter((e) => !e.match(/@[\d.]+|184|device:.+|patissier|ca/)) - .join("")}`, lastComment = index[key]; + .sort() + .filter((e) => !e.match(/@[\d.]+|184|device:.+|patissier|ca/)) + .join("")}`, + lastComment = index[key]; if (lastComment === undefined) { index[key] = comment; return true; } - if (comment.vpos - lastComment.vpos > config.sameCAGap || - Math.abs(comment.date - lastComment.date) < config.sameCARange) { + if ( + comment.vpos - lastComment.vpos > config.sameCAGap || + Math.abs(comment.date - lastComment.date) < config.sameCARange + ) { index[key] = comment; return true; } @@ -1035,8 +1109,7 @@ }; const getUser = (userId, users) => { const user = users.find((user) => user.userId === userId); - if (user) - return user; + if (user) return user; const obj = { userId, comments: [], @@ -1060,10 +1133,12 @@ }, []); }; const getTime = (time, times) => { - const timeObj = times.find((timeObj) => timeObj.range.start - config.sameCATimestampRange <= time && - timeObj.range.end + config.sameCATimestampRange >= time); - if (timeObj) - return timeObj; + const timeObj = times.find( + (timeObj) => + timeObj.range.start - config.sameCATimestampRange <= time && + timeObj.range.end + config.sameCATimestampRange >= time + ); + if (timeObj) return timeObj; const obj = { range: { start: time, @@ -1079,11 +1154,9 @@ return (a, b) => { if (getter(a) > getter(b)) { return 1; - } - else if (getter(a) < getter(b)) { + } else if (getter(a) < getter(b)) { return -1; - } - else { + } else { return 0; } }; @@ -1113,27 +1186,28 @@ return index; }; const getFlashFontName = (font) => { - if (font === "simsunStrong" || font === "simsunWeak") - return "simsun"; - if (font === "gothic") - return "defont"; + if (font === "simsunStrong" || font === "simsunWeak") return "simsun"; + if (font === "gothic") return "defont"; return font; }; const parseContent = (content) => { const results = []; - const lines = (content.match(/\n|[^\n]+/g) || []).map((val) => Array.from(val.match(/[ -~。-゚]+|[^ -~。-゚]+/g) || [])); + const lines = (content.match(/\n|[^\n]+/g) || []).map((val) => + Array.from(val.match(/[ -~。-゚]+|[^ -~。-゚]+/g) || []) + ); for (const line of lines) { const lineContent = parseLine(line); const firstContent = lineContent[0]; if (firstContent && firstContent.font) { - results.push(...lineContent.map((val) => { - if (!val.font) { - val.font = firstContent.font; - } - return val; - })); - } - else { + results.push( + ...lineContent.map((val) => { + if (!val.font) { + val.font = firstContent.font; + } + return val; + }) + ); + } else { results.push(...lineContent); } } @@ -1154,15 +1228,13 @@ const index = getFlashFontIndex(part); if (index.length === 0) { lineContent.push({ content: part, slicedContent: part.split("\n") }); - } - else if (index.length === 1 && index[0]) { + } else if (index.length === 1 && index[0]) { lineContent.push({ content: part, slicedContent: part.split("\n"), font: getFlashFontName(index[0].font), }); - } - else { + } else { parseMultiFontFullWidthPart(part, index, lineContent); } }; @@ -1171,9 +1243,9 @@ 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]; - if (currentVal === undefined || lastVal === undefined) - continue; + const currentVal = index[i], + lastVal = index[i - 1]; + if (currentVal === undefined || lastVal === undefined) continue; const content = part.slice(offset, currentVal.index); lineContent.push({ content: content, @@ -1193,7 +1265,8 @@ } return; } - const firstVal = index[0], secondVal = index[1]; + const firstVal = index[0], + secondVal = index[1]; if (!firstVal || !secondVal) { lineContent.push({ content: part, @@ -1225,23 +1298,32 @@ class TypeGuardError extends Error { constructor(options = {}) { - super("Type Guard Error\nAn error occurred due to unexpected values\nPlease contact the developer on GitHub", options); + super( + "Type Guard Error\nAn error occurred due to unexpected values\nPlease contact the developer on GitHub", + options + ); } } TypeGuardError.prototype.name = "TypeGuardError"; const getLineHeight = (fontSize, isFlash, resized = false) => { - const lineCounts = getConfig(config.lineCounts, isFlash), CommentStageSize = getConfig(config.CommentStageSize, isFlash), lineHeight = CommentStageSize.height / lineCounts.doubleResized[fontSize], defaultLineCount = lineCounts.default[fontSize]; + const lineCounts = getConfig(config.lineCounts, isFlash), + CommentStageSize = getConfig(config.CommentStageSize, isFlash), + lineHeight = CommentStageSize.height / lineCounts.doubleResized[fontSize], + defaultLineCount = lineCounts.default[fontSize]; if (resized) { const resizedLineCount = lineCounts.resized[fontSize]; - return ((CommentStageSize.height - + return ( + (CommentStageSize.height - lineHeight * (defaultLineCount / resizedLineCount)) / - (resizedLineCount - 1)); + (resizedLineCount - 1) + ); } return (CommentStageSize.height - lineHeight) / (defaultLineCount - 1); }; const getCharSize = (fontSize, isFlash) => { - const lineCounts = getConfig(config.lineCounts, isFlash), CommentStageSize = getConfig(config.CommentStageSize, isFlash); + const lineCounts = getConfig(config.lineCounts, isFlash), + CommentStageSize = getConfig(config.CommentStageSize, isFlash); return CommentStageSize.height / lineCounts.doubleResized[fontSize]; }; const measure = (comment, context) => { @@ -1252,7 +1334,9 @@ }; }; const measureWidth = (comment, context) => { - const { fontSize, scale } = getFontSizeAndScale(comment.charSize), lineWidth = [], itemWidth = []; + const { fontSize, scale } = getFontSizeAndScale(comment.charSize), + lineWidth = [], + itemWidth = []; context.font = parseFont(comment.font, fontSize); let currentWidth = 0; for (const item of comment.content) { @@ -1261,8 +1345,7 @@ const width = []; for (let j = 0, n = lines.length; j < n; j++) { const line = lines[j]; - if (line === undefined) - throw new TypeGuardError(); + if (line === undefined) throw new TypeGuardError(); const measure = context.measureText(line); currentWidth += measure.width; width.push(measure.width); @@ -1283,8 +1366,7 @@ const getFontSizeAndScale = (charSize) => { charSize *= 0.8; if (charSize < config.minFontSize) { - if (charSize >= 1) - charSize = Math.floor(charSize); + if (charSize >= 1) charSize = Math.floor(charSize); return { scale: charSize / config.minFontSize, fontSize: config.minFontSize, @@ -1296,7 +1378,7 @@ }; }; - var index$1 = /*#__PURE__*/Object.freeze({ + var index$1 = /*#__PURE__*/ Object.freeze({ __proto__: null, ArrayEqual: ArrayEqual, ArrayPush: ArrayPush, @@ -1323,7 +1405,7 @@ parseContent: parseContent, parseFont: parseFont, processFixedComment: processFixedComment, - processMovableComment: processMovableComment + processMovableComment: processMovableComment, }); const generateCanvas = () => { @@ -1331,8 +1413,7 @@ }; const getContext = (canvas) => { const context = canvas.getContext("2d"); - if (!context) - throw new CanvasRenderingContext2DError(); + if (!context) throw new CanvasRenderingContext2DError(); return context; }; const drawImage = (targetContext, sourceImage, x, y) => { @@ -1397,8 +1478,14 @@ throw new NotImplementedError(this.pluginName, "getCommentSize"); } parseCommandAndNicoscript(comment) { - console.error("parseCommandAndNicoscript method is not implemented", comment); - throw new NotImplementedError(this.pluginName, "parseCommandAndNicoscript"); + console.error( + "parseCommandAndNicoscript method is not implemented", + comment + ); + throw new NotImplementedError( + this.pluginName, + "parseCommandAndNicoscript" + ); } parseContent(comment) { console.error("parseContent method is not implemented", comment); @@ -1413,13 +1500,13 @@ throw new NotImplementedError(this.pluginName, "convertComment"); } draw(vpos, showCollision, debug) { - if (isBanActive(vpos)) - return; + if (isBanActive(vpos)) return; const reverse = isReverseActive(vpos, this.comment.owner); const posX = getPosX(this.comment, vpos, reverse); - const posY = this.comment.loc === "shita" - ? config.canvasHeight - this.posY - this.comment.height - : this.posY; + const posY = + this.comment.loc === "shita" + ? config.canvasHeight - this.posY - this.comment.height + : this.posY; this._drawBackgroundColor(posX, posY); this._draw(posX, posY); this._drawRectColor(posX, posY); @@ -1434,8 +1521,7 @@ this.context.save(); if (this.comment._live) { this.context.globalAlpha = config.contextFillLiveOpacity; - } - else { + } else { this.context.globalAlpha = 1; } drawImage(this.context, this.image, posX, posY); @@ -1446,7 +1532,12 @@ if (this.comment.wakuColor) { this.context.save(); this.context.strokeStyle = this.comment.wakuColor; - this.context.strokeRect(posX, posY, this.comment.width, this.comment.height); + this.context.strokeRect( + posX, + posY, + this.comment.width, + this.comment.height + ); this.context.restore(); } } @@ -1454,7 +1545,12 @@ if (this.comment.fillColor) { this.context.save(); this.context.fillStyle = this.comment.fillColor; - this.context.fillRect(posX, posY, this.comment.width, this.comment.height); + this.context.fillRect( + posX, + posY, + this.comment.width, + this.comment.height + ); this.context.restore(); } } @@ -1472,14 +1568,22 @@ } } _drawCollision(posX, posY, showCollision) { - console.error("_drawCollision method is not implemented", posX, posY, showCollision); + console.error( + "_drawCollision method is not implemented", + posX, + posY, + showCollision + ); throw new NotImplementedError(this.pluginName, "_drawCollision"); } getTextImage() { - if (this.comment.invisible || + if ( + this.comment.invisible || (this.comment.lineCount === 1 && this.comment.width === 0) || - this.comment.height - (this.comment.charSize - this.comment.lineHeight) <= - 0) + this.comment.height - + (this.comment.charSize - this.comment.lineHeight) <= + 0 + ) return null; const cache = imageCache[this.cacheKey]; if (cache) { @@ -1493,8 +1597,7 @@ }, this.comment.long * 10 + config.cacheAge); return cache.image; } - if (this.image) - return this.image; + if (this.image) return this.image; const image = this._generateTextImage(); this._cacheImage(image); return image; @@ -1601,7 +1704,9 @@ } parseCommandAndNicoscript(comment) { const data = parseCommandAndNicoScript(comment); - const { content, lineCount, lineOffset } = this.parseContent(comment.content); + const { content, lineCount, lineOffset } = this.parseContent( + comment.content + ); const val = content[0]; if (val && val.font) { data.font = val.font; @@ -1620,12 +1725,14 @@ const lineCount = content.reduce((pv, val) => { return pv + (val.content.match(/\n/g)?.length || 0); }, 1); - const lineOffset = (input.match(new RegExp(config.FlashScriptChar.super, "g"))?.length || + const lineOffset = + (input.match(new RegExp(config.FlashScriptChar.super, "g"))?.length || 0) * - -1 * - config.scriptCharOffset + - (input.match(new RegExp(config.FlashScriptChar.sub, "g"))?.length || 0) * - config.scriptCharOffset; + -1 * + config.scriptCharOffset + + (input.match(new RegExp(config.FlashScriptChar.sub, "g"))?.length || + 0) * + config.scriptCharOffset; return { content, lineCount, @@ -1633,7 +1740,8 @@ }; } measureText(comment) { - const configLineHeight = getConfig(config.lineHeight, true), configFontSize = getConfig(config.fontSize, true); + const configLineHeight = getConfig(config.lineHeight, true), + configFontSize = getConfig(config.fontSize, true); const lineCount = comment.lineCount; comment.lineHeight ??= configLineHeight[comment.size].default; if (isLineBreakResize(comment)) { @@ -1645,7 +1753,8 @@ } const { width_arr, spacedWidth_arr } = this._measureContent(comment); const leadLine = (function () { - let max = 0, index = -1; + let max = 0, + index = -1; spacedWidth_arr.forEach((val, i) => { if (max < val) { max = val; @@ -1657,11 +1766,14 @@ const width = leadLine.max; const scaleX = leadLine.max / (width_arr[leadLine.index] ?? 1); const width_max = width * comment.scale; - const height = (comment.fontSize * comment.lineHeight * lineCount + + const height = + (comment.fontSize * comment.lineHeight * lineCount + config.commentYPaddingTop[comment.resizedY ? "resized" : "default"]) * comment.scale; if (comment.loc !== "naka") { - const widthLimit = getConfig(config.CommentStageSize, true)[comment.full ? "fullWidth" : "width"]; + const widthLimit = getConfig(config.CommentStageSize, true)[ + comment.full ? "fullWidth" : "width" + ]; if (width_max > widthLimit && !comment.resizedX) { comment.fontSize = configFontSize[comment.size].default; comment.lineHeight = configLineHeight[comment.size].default; @@ -1671,7 +1783,9 @@ return this.measureText(comment); } } - if (!typeGuard.internal.CommentMeasuredContentItemArray(comment.content)) { + if ( + !typeGuard.internal.CommentMeasuredContentItemArray(comment.content) + ) { throw new TypeGuardError(); } return { @@ -1689,20 +1803,25 @@ }; } _measureContent(comment) { - const width_arr = [], spacedWidth_arr = []; - let currentWidth = 0, spacedWidth = 0; + const width_arr = [], + spacedWidth_arr = []; + let currentWidth = 0, + spacedWidth = 0; for (const item of comment.content) { const lines = item.content.split("\n"); const widths = []; - this.context.font = parseFont(item.font || comment.font, comment.fontSize); + this.context.font = parseFont( + item.font || comment.font, + comment.fontSize + ); for (let i = 0, n = lines.length; i < n; i++) { const value = lines[i]; - if (value === undefined) - continue; + if (value === undefined) continue; const measure = this.context.measureText(value); currentWidth += measure.width; spacedWidth += - measure.width + Math.max(value.length - 1, 0) * config.letterSpacing; + measure.width + + Math.max(value.length - 1, 0) * config.letterSpacing; widths.push(measure.width); if (i < lines.length - 1) { width_arr.push(currentWidth); @@ -1721,18 +1840,31 @@ if (showCollision) { this.context.save(); this.context.strokeStyle = "rgba(255,0,255,1)"; - this.context.strokeRect(posX, posY, this.comment.width, this.comment.height); + this.context.strokeRect( + posX, + posY, + this.comment.width, + this.comment.height + ); for (let i = 0, n = this.comment.lineCount; i < n; i++) { - const linePosY = ((i + 1) * (this.comment.fontSize * this.comment.lineHeight) + - config.commentYPaddingTop[this.comment.resizedY ? "resized" : "default"]) * + const linePosY = + ((i + 1) * (this.comment.fontSize * this.comment.lineHeight) + + config.commentYPaddingTop[ + this.comment.resizedY ? "resized" : "default" + ]) * this.comment.scale; this.context.strokeStyle = `rgba(255,255,0,0.25)`; - this.context.strokeRect(posX, posY + linePosY * this._globalScale, this.comment.width, this.comment.fontSize * - this.comment.lineHeight * - -1 * - this._globalScale * - this.comment.scale * - (this.comment.layer === -1 ? options.scale : 1)); + this.context.strokeRect( + posX, + posY + linePosY * this._globalScale, + this.comment.width, + this.comment.fontSize * + this.comment.lineHeight * + -1 * + this._globalScale * + this.comment.scale * + (this.comment.layer === -1 ? options.scale : 1) + ); } this.context.restore(); } @@ -1745,19 +1877,24 @@ context.fillStyle = this.comment.color; context.textAlign = "start"; context.textBaseline = "alphabetic"; + context.lineJoin = "bevel"; context.lineWidth = 4; context.font = parseFont(this.comment.font, this.comment.fontSize); - const scale = this._globalScale * + const scale = + this._globalScale * this.comment.scale * (this.comment.layer === -1 ? options.scale : 1); context.scale(scale * this.comment.scaleX, scale); const lineOffset = this.comment.lineOffset; const offsetKey = this.comment.resizedY ? "resized" : "default"; - const offsetY = config.commentYPaddingTop[offsetKey] + + const offsetY = + config.commentYPaddingTop[offsetKey] + this.comment.fontSize * - this.comment.lineHeight * - config.commentYOffset[this.comment.size][offsetKey]; - let lastFont = this.comment.font, leftOffset = 0, lineCount = 0; + this.comment.lineHeight * + config.commentYOffset[this.comment.size][offsetKey]; + let lastFont = this.comment.font, + leftOffset = 0, + lineCount = 0; for (const item of this.comment.content) { const font = item.font || this.comment.font; if (lastFont !== font) { @@ -1767,10 +1904,10 @@ const lines = item.slicedContent; for (let j = 0, n = lines.length; j < n; j++) { const line = lines[j]; - if (line === undefined) - continue; - const posY = (lineOffset + lineCount + 1) * - (this.comment.fontSize * this.comment.lineHeight) + + if (line === undefined) continue; + const posY = + (lineOffset + lineCount + 1) * + (this.comment.fontSize * this.comment.lineHeight) + offsetY; context.strokeText(line, leftOffset, posY); context.fillText(line, leftOffset, posY); @@ -1858,7 +1995,9 @@ } parseCommandAndNicoscript(comment) { const data = parseCommandAndNicoScript(comment); - const { content, lineCount, lineOffset } = this.parseContent(comment.content); + const { content, lineCount, lineOffset } = this.parseContent( + comment.content + ); return { ...comment, rawContent: comment.content, @@ -1886,11 +2025,11 @@ } measureText(comment) { const scale = getConfig(config.commentScale, false); - const configFontSize = getConfig(config.fontSize, false), lineHeight = getLineHeight(comment.size, false), charSize = getCharSize(comment.size, false); - if (!comment.lineHeight) - comment.lineHeight = lineHeight; - if (!comment.charSize) - comment.charSize = charSize; + const configFontSize = getConfig(config.fontSize, false), + lineHeight = getLineHeight(comment.size, false), + charSize = getCharSize(comment.size, false); + if (!comment.lineHeight) comment.lineHeight = lineHeight; + if (!comment.charSize) comment.charSize = charSize; comment.fontSize = comment.charSize * 0.8; this.context.font = parseFont(comment.font, comment.fontSize); if (isLineBreakResize(comment)) { @@ -1904,12 +2043,13 @@ const { width, height, itemWidth } = this._measureComment(comment); for (let i = 0, n = comment.content.length; i < n; i++) { const item = comment.content[i]; - if (!item || !itemWidth) - continue; + if (!item || !itemWidth) continue; item.width = itemWidth[i]; } comment.fontSize = (comment.charSize ?? 0) * 0.8; - if (!typeGuard.internal.CommentMeasuredContentItemArray(comment.content)) { + if ( + !typeGuard.internal.CommentMeasuredContentItemArray(comment.content) + ) { throw new TypeGuardError(); } return { @@ -1927,9 +2067,10 @@ }; } _measureComment(comment) { - const widthLimit = getConfig(config.CommentStageSize, false)[comment.full ? "fullWidth" : "width"]; - if (!typeGuard.internal.MeasureInput(comment)) - throw new TypeGuardError(); + const widthLimit = getConfig(config.CommentStageSize, false)[ + comment.full ? "fullWidth" : "width" + ]; + if (!typeGuard.internal.MeasureInput(comment)) throw new TypeGuardError(); const measureResult = measure(comment, this.context); if (comment.loc !== "naka" && measureResult.width > widthLimit) { return this._processResizeX(comment, measureResult.width); @@ -1937,7 +2078,9 @@ return measureResult; } _processResizeX(comment, width) { - const widthLimit = getConfig(config.CommentStageSize, false)[comment.full ? "fullWidth" : "width"]; + const widthLimit = getConfig(config.CommentStageSize, false)[ + comment.full ? "fullWidth" : "width" + ]; const lineHeight = getLineHeight(comment.size, false); const charSize = getCharSize(comment.size, false); const scale = widthLimit / width; @@ -1957,8 +2100,7 @@ _comment.fontSize = _comment.charSize * 0.8; result = measure(_comment, this.context); } - } - else { + } else { let lastComment = { ..._comment }; while (result.width < widthLimit) { lastComment = { ..._comment }; @@ -1974,14 +2116,12 @@ const scale = (_comment.charSize ?? 0) / (comment.charSize ?? 0); comment.charSize = scale * charSize; comment.lineHeight = scale * lineHeight; - } - else { + } else { comment.charSize = _comment.charSize; comment.lineHeight = _comment.lineHeight; } comment.fontSize = (comment.charSize ?? 0) * 0.8; - if (!typeGuard.internal.MeasureInput(comment)) - throw new TypeGuardError(); + if (!typeGuard.internal.MeasureInput(comment)) throw new TypeGuardError(); return measure(comment, this.context); } _drawCollision(posX, posY, showCollision) { @@ -1989,24 +2129,36 @@ this.context.save(); const scale = getConfig(config.commentScale, false); this.context.strokeStyle = "rgba(0,255,255,1)"; - this.context.strokeRect(posX, posY, this.comment.width, this.comment.height); + this.context.strokeRect( + posX, + posY, + this.comment.width, + this.comment.height + ); for (let i = 0, n = this.comment.lineCount; i < n; i++) { if (!typeGuard.internal.HTML5Fonts(this.comment.font)) throw new TypeGuardError(); - const linePosY = (this.comment.lineHeight * (i + 1) + + const linePosY = + (this.comment.lineHeight * (i + 1) + (this.comment.charSize - this.comment.lineHeight) / 2 + this.comment.lineHeight * -0.16 + (config.fonts[this.comment.font]?.offset || 0)) * scale; this.context.strokeStyle = "rgba(255,255,0,0.5)"; - this.context.strokeRect(posX, posY + linePosY, this.comment.width, this.comment.fontSize * -1 * scale); + this.context.strokeRect( + posX, + posY + linePosY, + this.comment.width, + this.comment.fontSize * -1 * scale + ); } this.context.restore(); } } _generateTextImage() { const { fontSize, scale } = getFontSizeAndScale(this.comment.charSize); - const paddingTop = (10 - scale * 10) * + const paddingTop = + (10 - scale * 10) * ((this.comment.lineCount + 1) / config.hiResCommentCorrection); const { image, context } = this.createCanvas(); image.width = this.comment.width + 2 * 2 * this.comment.charSize; @@ -2017,25 +2169,28 @@ context.fillStyle = this.comment.color; context.textAlign = "start"; context.textBaseline = "alphabetic"; + context.lineJoin = "bevel"; context.lineWidth = config.contextLineWidth; context.font = parseFont(this.comment.font, fontSize); - const drawScale = getConfig(config.commentScale, false) * + const drawScale = + getConfig(config.commentScale, false) * scale * (this.comment.layer === -1 ? options.scale : 1); context.scale(drawScale, drawScale); let lineCount = 0; if (!typeGuard.internal.HTML5Fonts(this.comment.font)) throw new TypeGuardError(); - const offsetY = (this.comment.charSize - this.comment.lineHeight) / 2 + + const offsetY = + (this.comment.charSize - this.comment.lineHeight) / 2 + this.comment.lineHeight * -0.16 + (config.fonts[this.comment.font]?.offset || 0); for (const item of this.comment.content) { const lines = item.slicedContent; for (let j = 0, n = lines.length; j < n; j++) { const line = lines[j]; - if (line === undefined) - continue; - const posY = (this.comment.lineHeight * (lineCount + 1 + paddingTop) + offsetY) / + if (line === undefined) continue; + const posY = + (this.comment.lineHeight * (lineCount + 1 + paddingTop) + offsetY) / scale; context.strokeText(line, 0, posY); context.fillText(line, 0, posY); @@ -2046,21 +2201,24 @@ } } - var index = /*#__PURE__*/Object.freeze({ + var index = /*#__PURE__*/ Object.freeze({ __proto__: null, BaseComment: BaseComment, FlashComment: FlashComment, - HTML5Comment: HTML5Comment + HTML5Comment: HTML5Comment, }); const build = (fonts) => { - return fonts.reduce((pv, val, index) => { - if (index === 0) { - return { ...val }; - } - pv.font += `, ${val.font}`; - return pv; - }, { font: "", offset: 0, weight: 600 }); + return fonts.reduce( + (pv, val, index) => { + if (index === 0) { + return { ...val }; + } + pv.font += `, ${val.font}`; + return pv; + }, + { font: "", offset: 0, weight: 600 } + ); }; const fontTemplates = { arial: { @@ -2191,28 +2349,24 @@ }, }; - var fonts$1 = /*#__PURE__*/Object.freeze({ + var fonts$1 = /*#__PURE__*/ Object.freeze({ __proto__: null, fontTemplates: fontTemplates, - fonts: fonts + fonts: fonts, }); const initConfig = () => { const platform = (function (ua) { - if (ua.match(/windows nt 6\.[12]/i)) - return "win7"; - else if (ua.match(/windows nt (6\.3|10\.\d+)|win32/i)) - return "win8_1"; - else if (ua.match(/windows nt/i)) - return "win"; - else if (ua.match(/mac os x 10(.|_)(9|10)/i)) - return "mac10_9"; - else if (ua.match(/mac os x 10(.|_)\d{2}|darwin/i)) - return "mac10_11"; - else if (ua.match(/mac os x/i)) - return "mac"; + if (ua.match(/windows nt 6\.[12]/i)) return "win7"; + else if (ua.match(/windows nt (6\.3|10\.\d+)|win32/i)) return "win8_1"; + else if (ua.match(/windows nt/i)) return "win"; + else if (ua.match(/mac os x 10(.|_)(9|10)/i)) return "mac10_9"; + else if (ua.match(/mac os x 10(.|_)\d{2}|darwin/i)) return "mac10_11"; + else if (ua.match(/mac os x/i)) return "mac"; return "other"; - })(typeof navigator !== "undefined" ? navigator.userAgent : process.platform); + })( + typeof navigator !== "undefined" ? navigator.userAgent : process.platform + ); const defaultConfig = { colors: colors, contextStrokeColor: "#000000", @@ -2303,19 +2457,25 @@ plugins: [], flashThreshold: 1499871600, flashChar: { - gulim: "[\u0126\u0127\u0132\u0133\u0138\u013f\u0140\u0149-\u014b\u0166\u0167\u02d0\u02da\u2074\u207f\u2081-\u2084\u2113\u2153\u2154\u215c-\u215e\u2194\u2195\u223c\u249c-\u24b5\u24d0-\u24e9\u25a3-\u25a9\u25b6\u25b7\u25c0\u25c1\u25c8\u25d0\u25d1\u260e\u260f\u261c\u261e\u2660\u2661\u2663-\u2665\u2667-\u2669\u266c\u3131-\u316e\u3200-\u321c\u3260-\u327b\u3380-\u3384\u3388-\u338d\u3390-\u339b\u339f\u33a0\u33a2-\u33ca\u33cf\u33d0\u33d3\u33d6\u33d8\u33db-\u33dd\uf900-\uf928\uf92a-\uf994\uf996\ufa0b\uffe6]", - simsunStrong: "[\u01ce\u01d0\u01d2\u01d4\u01d6\u01d8\u01da\u01dc\u0251\u0261\u02ca\u02cb\u2016\u2035\u216a\u216b\u2223\u2236\u2237\u224c\u226e\u226f\u2295\u2483-\u249b\u2504-\u250b\u256d-\u2573\u2581-\u2583\u2585-\u2587\u2589-\u258b\u258d-\u258f\u2594\u2595\u25e2-\u25e5\u2609\u3016\u3017\u301e\u3021-\u3029\u3105-\u3129\u3220-\u3229\u32a3\u33ce\u33d1\u33d2\u33d5\ue758-\ue864\ufa0c\ufa0d\ufe30\ufe31\ufe33-\ufe44\ufe49-\ufe52\ufe54-\ufe57\ufe59-\ufe66\ufe68-\ufe6b]", - simsunWeak: "[\u02c9\u2105\u2109\u2196-\u2199\u220f\u2215\u2248\u2264\u2265\u2299\u2474-\u2482\u250d\u250e\u2511\u2512\u2515\u2516\u2519\u251a\u251e\u251f\u2521\u2522\u2526\u2527\u2529\u252a\u252d\u252e\u2531\u2532\u2535\u2536\u2539\u253a\u253d\u253e\u2540\u2541\u2543-\u254a\u2550-\u256c\u2584\u2588\u258c\u2593]", + gulim: + "[\u0126\u0127\u0132\u0133\u0138\u013f\u0140\u0149-\u014b\u0166\u0167\u02d0\u02da\u2074\u207f\u2081-\u2084\u2113\u2153\u2154\u215c-\u215e\u2194\u2195\u223c\u249c-\u24b5\u24d0-\u24e9\u25a3-\u25a9\u25b6\u25b7\u25c0\u25c1\u25c8\u25d0\u25d1\u260e\u260f\u261c\u261e\u2660\u2661\u2663-\u2665\u2667-\u2669\u266c\u3131-\u316e\u3200-\u321c\u3260-\u327b\u3380-\u3384\u3388-\u338d\u3390-\u339b\u339f\u33a0\u33a2-\u33ca\u33cf\u33d0\u33d3\u33d6\u33d8\u33db-\u33dd\uf900-\uf928\uf92a-\uf994\uf996\ufa0b\uffe6]", + simsunStrong: + "[\u01ce\u01d0\u01d2\u01d4\u01d6\u01d8\u01da\u01dc\u0251\u0261\u02ca\u02cb\u2016\u2035\u216a\u216b\u2223\u2236\u2237\u224c\u226e\u226f\u2295\u2483-\u249b\u2504-\u250b\u256d-\u2573\u2581-\u2583\u2585-\u2587\u2589-\u258b\u258d-\u258f\u2594\u2595\u25e2-\u25e5\u2609\u3016\u3017\u301e\u3021-\u3029\u3105-\u3129\u3220-\u3229\u32a3\u33ce\u33d1\u33d2\u33d5\ue758-\ue864\ufa0c\ufa0d\ufe30\ufe31\ufe33-\ufe44\ufe49-\ufe52\ufe54-\ufe57\ufe59-\ufe66\ufe68-\ufe6b]", + simsunWeak: + "[\u02c9\u2105\u2109\u2196-\u2199\u220f\u2215\u2248\u2264\u2265\u2299\u2474-\u2482\u250d\u250e\u2511\u2512\u2515\u2516\u2519\u251a\u251e\u251f\u2521\u2522\u2526\u2527\u2529\u252a\u252d\u252e\u2531\u2532\u2535\u2536\u2539\u253a\u253d\u253e\u2540\u2541\u2543-\u254a\u2550-\u256c\u2584\u2588\u258c\u2593]", gothic: "[\u03fb\uff9f]", }, FlashMode: "vista", FlashScriptChar: { - super: "[\u00aa\u00b2\u00b3\u00b9\u00ba\u02b0\u02b2\u02b3\u02b7\u02b8\u02e1-\u02e3\u0304\u1d2c-\u1d43\u1d45-\u1d61\u1d9b-\u1da1\u1da3-\u1dbf\u2070\u2071\u2074-\u207f\u2c7d]", + super: + "[\u00aa\u00b2\u00b3\u00b9\u00ba\u02b0\u02b2\u02b3\u02b7\u02b8\u02e1-\u02e3\u0304\u1d2c-\u1d43\u1d45-\u1d61\u1d9b-\u1da1\u1da3-\u1dbf\u2070\u2071\u2074-\u207f\u2c7d]", sub: "[\u0320\u1d62-\u1d6a\u2080-\u208e\u2090-\u209c\u2c7c]", }, font: { - gulim: 'normal 600 [size]px gulim, "Microsoft JhengHei UI", Arial, "MS Pゴシック", "MS PGothic", MSPGothic, MS-PGothic', - simsun: 'normal 400 [size]px simsun, "游明朝体", "游明朝", "Yu Mincho", YuMincho, yumincho, YuMin-Medium', + gulim: + 'normal 600 [size]px gulim, "Microsoft JhengHei UI", Arial, "MS Pゴシック", "MS PGothic", MSPGothic, MS-PGothic', + simsun: + 'normal 400 [size]px simsun, "游明朝体", "游明朝", "Yu Mincho", YuMincho, yumincho, YuMin-Medium', }, lineHeight: { small: { @@ -2369,9 +2529,9 @@ updateConfig(defaultConfig); }; - var initConfig$1 = /*#__PURE__*/Object.freeze({ + var initConfig$1 = /*#__PURE__*/ Object.freeze({ __proto__: null, - initConfig: initConfig + initConfig: initConfig, }); let handlerList = []; @@ -2387,13 +2547,17 @@ updateEventHandlerCounts(); }; const removeHandler = (eventName, handler) => { - handlerList = handlerList.filter((item) => item.eventName !== eventName || item.handler !== handler); + handlerList = handlerList.filter( + (item) => item.eventName !== eventName || item.handler !== handler + ); updateEventHandlerCounts(); }; const updateEventHandlerCounts = () => { for (const key_ of Object.keys(handlerCounts)) { const key = key_; - handlerCounts[key] = handlerList.filter((item) => item.eventName === key).length; + handlerCounts[key] = handlerList.filter( + (item) => item.eventName === key + ).length; } }; const triggerHandler = (vpos, lastVpos) => { @@ -2405,15 +2569,15 @@ 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, + lastVposInRange = range.start < lastVpos && lastVpos < range.end; if (vposInRange && !lastVposInRange) { executeEvents("commentDisable", { type: "commentDisable", timeStamp: new Date().getTime(), vpos: vpos, }); - } - else if (!vposInRange && lastVposInRange) { + } else if (!vposInRange && lastVposInRange) { executeEvents("commentEnable", { type: "commentEnable", timeStamp: new Date().getTime(), @@ -2423,18 +2587,17 @@ } }; const processSeekDisableScript = (vpos, lastVpos) => { - if (handlerCounts.seekDisable < 1 && handlerCounts.seekEnable < 1) - return; + 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, + lastVposInRange = range.start < lastVpos && lastVpos < range.end; if (vposInRange && !lastVposInRange) { executeEvents("seekDisable", { type: "seekDisable", timeStamp: new Date().getTime(), vpos: vpos, }); - } - else if (!vposInRange && lastVposInRange) { + } else if (!vposInRange && lastVposInRange) { executeEvents("seekEnable", { type: "seekEnable", timeStamp: new Date().getTime(), @@ -2444,10 +2607,12 @@ } }; const processJumpScript = (vpos, lastVpos) => { - if (handlerCounts.jump < 1) - return; + 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), + lastVposInRange = + range.start < lastVpos && (!range.end || lastVpos < range.end); if (vposInRange && !lastVposInRange) { executeEvents("jump", { type: "jump", @@ -2461,54 +2626,51 @@ }; const executeEvents = (eventName, event) => { for (const item of handlerList) { - if (eventName !== item.eventName) - continue; + if (eventName !== item.eventName) continue; item.handler(event); } }; - var eventHandler = /*#__PURE__*/Object.freeze({ + var eventHandler = /*#__PURE__*/ Object.freeze({ __proto__: null, registerHandler: registerHandler, removeHandler: removeHandler, - triggerHandler: triggerHandler + triggerHandler: triggerHandler, }); const convert2formattedComment = (data, type) => { let result = []; if (type === "empty" && data === undefined) { return []; - } - else if ((type === "XMLDocument" || type === "niconicome") && - typeGuard.xmlDocument(data)) { + } else if ( + (type === "XMLDocument" || type === "niconicome") && + typeGuard.xmlDocument(data) + ) { result = fromXMLDocument(data); - } - else if (type === "formatted" && typeGuard.formatted.legacyComments(data)) { + } else if ( + type === "formatted" && + typeGuard.formatted.legacyComments(data) + ) { result = fromFormatted(data); - } - else if (type === "legacy" && typeGuard.legacy.rawApiResponses(data)) { + } else if (type === "legacy" && typeGuard.legacy.rawApiResponses(data)) { result = fromLegacy(data); - } - else if (type === "legacyOwner" && typeGuard.legacyOwner.comments(data)) { + } else if (type === "legacyOwner" && typeGuard.legacyOwner.comments(data)) { result = fromLegacyOwner(data); - } - else if (type === "owner" && typeGuard.owner.comments(data)) { + } else if (type === "owner" && typeGuard.owner.comments(data)) { result = fromOwner(data); - } - else if (type === "v1" && typeGuard.v1.threads(data)) { + } else if (type === "v1" && typeGuard.v1.threads(data)) { result = fromV1(data); - } - else { + } else { throw new InvalidFormatError(); } return sort(result); }; const fromXMLDocument = (data) => { - const data_ = [], userList = []; + const data_ = [], + userList = []; let index = Array.from(data.documentElement.children).length; for (const item of Array.from(data.documentElement.children)) { - if (item.nodeName !== "chat") - continue; + if (item.nodeName !== "chat") continue; const tmpParam = { id: Number(item.getAttribute("no")) || index++, vpos: Number(item.getAttribute("vpos")), @@ -2532,8 +2694,7 @@ if (isUserExist === -1) { tmpParam.user_id = userList.length; userList.push(userId); - } - else { + } else { tmpParam.user_id = isUserExist; } data_.push(tmpParam); @@ -2553,10 +2714,10 @@ }); }; const fromLegacy = (data) => { - const data_ = [], userList = []; + const data_ = [], + userList = []; for (const val of data) { - if (!typeGuard.legacy.apiChat(val.chat)) - continue; + if (!typeGuard.legacy.apiChat(val.chat)) continue; const value = val.chat; if (value.deleted !== 1) { const tmpParam = { @@ -2581,8 +2742,7 @@ if (isUserExist === -1) { tmpParam.user_id = userList.length; userList.push(value.user_id); - } - else { + } else { tmpParam.user_id = isUserExist; } data_.push(tmpParam); @@ -2591,16 +2751,15 @@ return data_; }; const fromLegacyOwner = (data) => { - const data_ = [], comments = data.split("\n"); + const data_ = [], + comments = data.split("\n"); for (let i = 0, n = comments.length; i < n; i++) { const value = comments[i]; - if (!value) - continue; + if (!value) continue; const commentData = value.split(":"); if (commentData.length < 3) { continue; - } - else if (commentData.length > 3) { + } else if (commentData.length > 3) { for (let j = 3, n = commentData.length; j < n; j++) { commentData[2] += `:${commentData[j]}`; } @@ -2631,8 +2790,7 @@ const data_ = []; for (let i = 0, n = data.length; i < n; i++) { const value = data[i]; - if (!value) - continue; + if (!value) continue; const tmpParam = { id: i, vpos: time2vpos(value.time), @@ -2656,9 +2814,11 @@ return data_; }; const fromV1 = (data) => { - const data_ = [], userList = []; + const data_ = [], + userList = []; for (const item of data) { - const val = item.comments, forkName = item.fork; + const val = item.comments, + forkName = item.fork; for (const value of val) { const tmpParam = { id: value.no, @@ -2679,8 +2839,7 @@ if (isUserExist === -1) { tmpParam.user_id = userList.length; userList.push(value.userId); - } - else { + } else { tmpParam.user_id = isUserExist; } data_.push(tmpParam); @@ -2690,39 +2849,38 @@ }; const sort = (data) => { data.sort((a, b) => { - if (a.vpos < b.vpos) - return -1; - if (a.vpos > b.vpos) - return 1; - if (a.date < b.date) - return -1; - if (a.date > b.date) - return 1; - if (a.date_usec < b.date_usec) - return -1; - if (a.date_usec > b.date_usec) - return 1; + if (a.vpos < b.vpos) return -1; + if (a.vpos > b.vpos) return 1; + if (a.date < b.date) return -1; + if (a.date > b.date) return 1; + if (a.date_usec < b.date_usec) return -1; + if (a.date_usec > b.date_usec) return 1; return 0; }); return data; }; const time2vpos = (time_str) => { - const time = time_str.match(/^(?:(\d+):(\d+)\.(\d+)|(\d+):(\d+)|(\d+)\.(\d+)|(\d+))$/); + const time = time_str.match( + /^(?:(\d+):(\d+)\.(\d+)|(\d+):(\d+)|(\d+)\.(\d+)|(\d+))$/ + ); if (time) { - if (time[1] !== undefined && + if ( + time[1] !== undefined && time[2] !== undefined && - time[3] !== undefined) { - return ((Number(time[1]) * 60 + Number(time[2])) * 100 + - Number(time[3]) / Math.pow(10, time[3].length - 2)); - } - else if (time[4] !== undefined && time[5] !== undefined) { + time[3] !== undefined + ) { + return ( + (Number(time[1]) * 60 + Number(time[2])) * 100 + + Number(time[3]) / Math.pow(10, time[3].length - 2) + ); + } else if (time[4] !== undefined && time[5] !== undefined) { return (Number(time[4]) * 60 + Number(time[5])) * 100; - } - else if (time[6] !== undefined && time[7] !== undefined) { - return (Number(time[6]) * 100 + - Number(time[7]) / Math.pow(10, time[7].length - 2)); - } - else if (time[8] !== undefined) { + } else if (time[6] !== undefined && time[7] !== undefined) { + return ( + Number(time[6]) * 100 + + Number(time[7]) / Math.pow(10, time[7].length - 2) + ); + } else if (time[8] !== undefined) { return Number(time[8]) * 100; } } @@ -2730,9 +2888,9 @@ }; const date2time = (date) => Math.floor(new Date(date).getTime() / 1000); - var inputParser = /*#__PURE__*/Object.freeze({ + var inputParser = /*#__PURE__*/ Object.freeze({ __proto__: null, - default: convert2formattedComment + default: convert2formattedComment, }); const createCommentInstance = (comment, context) => { @@ -2751,7 +2909,7 @@ initConfig: initConfig$1, }; - var internal = /*#__PURE__*/Object.freeze({ + var internal = /*#__PURE__*/ Object.freeze({ __proto__: null, comments: index, contexts: index$3, @@ -2760,7 +2918,7 @@ eventHandler: eventHandler, inputParser: inputParser, typeGuard: typeGuard$1, - utils: index$1 + utils: index$1, }); let isDebug = false; @@ -2796,16 +2954,21 @@ this.context = getContext(canvas); this.context.textAlign = "start"; this.context.textBaseline = "alphabetic"; + this.context.lineJoin = "bevel"; this.context.lineWidth = config.contextLineWidth; let formatType = options.format; if (options.formatted) { - console.warn("Deprecated: options.formatted is no longer recommended. Please use options.format. https://xpadev-net.github.io/niconicomments/#p_format"); + console.warn( + "Deprecated: options.formatted is no longer recommended. Please use options.format. https://xpadev-net.github.io/niconicomments/#p_format" + ); } if (formatType === "default") { formatType = options.formatted ? "formatted" : "legacy"; } if (options.useLegacy) { - console.warn("Deprecated: options.useLegacy is no longer recommended. Please use options.mode. https://xpadev-net.github.io/niconicomments/#p_mode"); + console.warn( + "Deprecated: options.useLegacy is no longer recommended. Please use options.mode. https://xpadev-net.github.io/niconicomments/#p_mode" + ); } if (options.mode === "default" && options.useLegacy) { options.mode = "html5"; @@ -2846,40 +3009,44 @@ canvas, instance: new plugin(canvas, instances), }); - } - catch (e) { + } catch (e) { console.error("Failed to init plugin"); } } setPlugins(plugins); - logger(`preRendering complete: ${performance.now() - preRenderingStart}ms`); + logger( + `preRendering complete: ${performance.now() - preRenderingStart}ms` + ); } getCommentPos(data) { const getCommentPosStart = performance.now(); for (const comment of data) { - if (comment.invisible) - continue; + if (comment.invisible) continue; if (comment.loc === "naka") { processMovableComment(comment, this.collision, this.timeline); - } - else { - processFixedComment(comment, this.collision[comment.loc], this.timeline); + } else { + processFixedComment( + comment, + this.collision[comment.loc], + this.timeline + ); } } - logger(`getCommentPos complete: ${performance.now() - getCommentPosStart}ms`); + logger( + `getCommentPos complete: ${performance.now() - getCommentPosStart}ms` + ); } sortComment() { const sortCommentStart = performance.now(); for (const vpos of Object.keys(this.timeline)) { const item = this.timeline[Number(vpos)]; - if (!item) - continue; - const owner = [], user = []; + if (!item) continue; + const owner = [], + user = []; for (const comment of item) { if (comment?.owner) { owner.push(comment); - } - else { + } else { user.push(comment); } } @@ -2895,37 +3062,41 @@ for (const plugin of plugins) { try { plugin.instance.addComments(comments); - } - catch (e) { + } catch (e) { console.error("Failed to add comments"); } } for (const comment of comments) { - if (comment.invisible) - continue; + if (comment.invisible) continue; if (comment.loc === "naka") { processMovableComment(comment, this.collision, this.timeline); - } - else { - processFixedComment(comment, this.collision[comment.loc], this.timeline); + } else { + processFixedComment( + comment, + this.collision[comment.loc], + this.timeline + ); } } } drawCanvas(vpos, forceRendering = false) { const drawCanvasStart = performance.now(); - if (this.lastVpos === vpos && !forceRendering) - return false; + if (this.lastVpos === vpos && !forceRendering) return false; triggerHandler(vpos, this.lastVpos); const timelineRange = this.timeline[vpos]; - if (!forceRendering && + if ( + !forceRendering && plugins.length === 0 && timelineRange?.filter((item) => item.loc === "naka").length === 0 && this.timeline[this.lastVpos]?.filter((item) => item.loc === "naka") - ?.length === 0) { - const current = timelineRange.filter((item) => item.loc !== "naka"), last = this.timeline[this.lastVpos]?.filter((item) => item.loc !== "naka") || - []; - if (ArrayEqual(current, last)) - return false; + ?.length === 0 + ) { + const current = timelineRange.filter((item) => item.loc !== "naka"), + last = + this.timeline[this.lastVpos]?.filter( + (item) => item.loc !== "naka" + ) || []; + if (ArrayEqual(current, last)) return false; } this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); this.lastVpos = vpos; @@ -2936,8 +3107,7 @@ try { plugin.instance.draw(vpos); this.context.drawImage(plugin.canvas, 0, 0); - } - catch (e) { + } catch (e) { console.error(`Failed to draw comments`); } } @@ -2949,15 +3119,23 @@ _drawVideo() { if (this.video) { let scale; - const height = this.canvas.height / this.video.videoHeight, width = this.canvas.width / this.video.videoWidth; + const height = this.canvas.height / this.video.videoHeight, + width = this.canvas.width / this.video.videoWidth; if (this.enableLegacyPiP ? height > width : height < width) { scale = width; - } - else { + } else { scale = height; } - const offsetX = (this.canvas.width - this.video.videoWidth * scale) * 0.5, offsetY = (this.canvas.height - this.video.videoHeight * scale) * 0.5; - this.context.drawImage(this.video, offsetX, offsetY, this.video.videoWidth * scale, this.video.videoHeight * scale); + const offsetX = + (this.canvas.width - this.video.videoWidth * scale) * 0.5, + offsetY = (this.canvas.height - this.video.videoHeight * scale) * 0.5; + this.context.drawImage( + this.video, + offsetX, + offsetY, + this.video.videoWidth * scale, + this.video.videoHeight * scale + ); } } _drawComments(timelineRange, vpos) { @@ -2982,16 +3160,27 @@ _drawCollision(vpos) { if (this.showCollision) { this.context.save(); - const leftCollision = this.collision.left[vpos], rightCollision = this.collision.right[vpos]; + const leftCollision = this.collision.left[vpos], + rightCollision = this.collision.right[vpos]; this.context.fillStyle = "red"; if (leftCollision) { for (const comment of leftCollision) { - this.context.fillRect(config.collisionRange.left, comment.posY, config.contextLineWidth, comment.height); + this.context.fillRect( + config.collisionRange.left, + comment.posY, + config.contextLineWidth, + comment.height + ); } } if (rightCollision) { for (const comment of rightCollision) { - this.context.fillRect(config.collisionRange.right, comment.posY, config.contextLineWidth * -1, comment.height); + this.context.fillRect( + config.collisionRange.right, + comment.posY, + config.contextLineWidth * -1, + comment.height + ); } } this.context.restore(); @@ -3002,7 +3191,9 @@ this.context.save(); this.context.font = parseFont("defont", 60); this.context.fillStyle = "#00FF00"; - this.context.strokeStyle = `rgba(${hex2rgb(config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`; + this.context.strokeStyle = `rgba(${hex2rgb( + config.contextStrokeColor + ).join(",")},${config.contextStrokeOpacity})`; const drawTime = Math.floor(performance.now() - drawCanvasStart); const fps = Math.floor(1000 / (drawTime === 0 ? 1 : drawTime)); this.context.strokeText(`FPS:${fps}(${drawTime}ms)`, 100, 100); @@ -3015,7 +3206,9 @@ this.context.save(); this.context.font = parseFont("defont", 60); this.context.fillStyle = "#00FF00"; - this.context.strokeStyle = `rgba(${hex2rgb(config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`; + this.context.strokeStyle = `rgba(${hex2rgb( + config.contextStrokeColor + ).join(",")},${config.contextStrokeOpacity})`; this.context.strokeText(`Count:${count || 0}`, 100, 200); this.context.fillText(`Count:${count || 0}`, 100, 200); this.context.restore(); @@ -3032,10 +3225,8 @@ } } const logger = (msg) => { - if (isDebug) - console.debug(msg); + if (isDebug) console.debug(msg); }; return NiconiComments; - -})); +});