diff --git a/README.md b/README.md index 6b4eee0..5f1bf20 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ | pause | Number | 当前文本输出完毕后的停顿时间。( `Echo.printSpeed * pause` ms ) | | speed | Number | 当前文本的打印速度,即每个打印循环所用时间(ms)。 | | typewrite | String | 模拟打字动作。在输出 `text` 字段的内容之前先打印此字段的内容,随后被 `text` 字段的内容替换。 | +| ruby | String | 文本顶部注释。 | | event | String | 自定义事件名。 | | data | Object | 自定义数据。 | @@ -56,6 +57,7 @@ | printSpeedChange | Number | 打印过程中的打印速度。 | 30 | | state | String | 运行状态。 | 'stop' | | typewrite | String | 打字动作状态。 | 'none' | +| ruby | Boolean | 是否正在打印包含注释的内容。 | false | | filter | Object | 过滤器状态开关。 | 见下文。 | | event | Object | 用于绑定事件。 | 略 | diff --git a/doc/event.md b/doc/event.md index 6b73f2a..4368752 100644 --- a/doc/event.md +++ b/doc/event.md @@ -60,6 +60,20 @@ ## printStart 打印开始事件,由 `print()` 方法触发。打印过程开始时触发。 +## rubyStart +包含注释内容的文本开始打印事件,由 `groupStart()` 方法触发。 + +| 参数类型 | 描述 | +| - | - | +| String | 注释内容。 | + +## rubyEnd +包含注释内容的文本打印结束事件,由 `groupEnd()` 方法触发。 + +| 参数类型 | 描述 | +| - | - | +| String | 注释内容。 | + ## send 发送消息事件,由 `send()` 方法触发。发送消息时触发,在 `printStart` 事件之前。 diff --git a/js/echo.js b/js/echo.js index d554d3f..d7d59d9 100644 --- a/js/echo.js +++ b/js/echo.js @@ -18,6 +18,7 @@ class Echo { this.printSpeedChange = 30; this.state = 'stop'; this.typewrite = 'none'; + this.ruby = false; this.filter = { HTMLFormat: true }; @@ -33,6 +34,8 @@ class Echo { print: function() {}, printEnd: function() {}, printStart: function() {}, + rubyEnd: function() {}, + rubyStart: function() {}, send: function() {}, sendList: function() {}, skip: function() {}, @@ -83,6 +86,10 @@ class Echo { groupNow: n } + if (obj?.ruby != undefined) { + this.ruby = false; + this.event.rubyEnd(obj.ruby); + } if (obj?.typewrite != undefined) { this.typewrite = 'ready'; } @@ -112,6 +119,10 @@ class Echo { this.event.customData(obj?.data); } this.event.groupStart(e); + if (obj?.ruby != undefined) { + this.ruby = true; + this.event.rubyStart(obj.ruby); + } return e; } @@ -134,6 +145,7 @@ class Echo { class: msg?.class, style: msg?.style, typewrite: msg?.typewrite, + ruby: msg?.ruby, printSpeed: msg?.speed, event: msg?.event, data: msg?.data @@ -141,7 +153,8 @@ class Echo { let dataAfter = { action: 'group_end', - typewrite: msg?.typewrite + typewrite: msg?.typewrite, + ruby: msg?.ruby }; let dataContent, data;