From b1d5660934454d5a3c3cd51ba3c8cbd21ad48968 Mon Sep 17 00:00:00 2001 From: MoeHero Date: Wed, 31 May 2017 16:08:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=B9=E5=B9=95=E5=A2=9E?= =?UTF-8?q?=E5=BC=BAbug=20=E6=B7=BB=E5=8A=A0=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E8=BD=AC=E4=B9=89=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/live/FuncDanmuEnhance.js | 2 +- src/live/Helper.js | 3 +++ src/live_inject.js | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/live/FuncDanmuEnhance.js b/src/live/FuncDanmuEnhance.js index 4000bc5..279602d 100644 --- a/src/live/FuncDanmuEnhance.js +++ b/src/live/FuncDanmuEnhance.js @@ -136,7 +136,7 @@ class FuncDanmuEnhance { } static sendDanmu_player(danmu) { return new Promise((resolve) => { - Helper.addScriptByText(`bh_sendDanmu(${danmu}, '0x'${this.danmuColorList[this.selectDanmuColor]}, ${this.selectDanmuMode});`).remove(); + Helper.addScriptByText(`bh_sendDanmu('${Helper.escape(danmu)}', '0x${this.danmuColorList[this.selectDanmuColor]}', ${this.selectDanmuMode});`).remove(); resolve(); }); } diff --git a/src/live/Helper.js b/src/live/Helper.js index 0295bce..a742af3 100644 --- a/src/live/Helper.js +++ b/src/live/Helper.js @@ -96,6 +96,9 @@ Helper.format = (template, data) => { } return template; }; +Helper.escape = string => { + return string.replace(/([\\'"&])+?/g, '\\$1'); +}; Helper.localize = {//TODO 重构 去除不必要文本 helper: 'Bilibili助手', enabled: '已启用', diff --git a/src/live_inject.js b/src/live_inject.js index be60f7b..42d079c 100644 --- a/src/live_inject.js +++ b/src/live_inject.js @@ -43,6 +43,6 @@ function bh_getDanmuInfo() { chrome.runtime.sendMessage(extensionID, {command: 'getDanmuInfo', danmuInfo: danmuInfo}); } function bh_sendDanmu(danmu, color, mode) { - window.LivePlayer && window.LivePlayer(danmu, color, mode); + window.LivePlayer && window.LivePlayer.sendMsg(danmu, color, mode); } console.log('%c直播间脚本注入成功~', 'color:#FFF;background-color:#57D2F7;padding:5px;border-radius:7px;line-height:30px;');