From 4622d346e780732c388bb79c39230e8268b4dc70 Mon Sep 17 00:00:00 2001 From: Shusui MOYATANI Date: Sat, 23 Jun 2018 14:37:31 +0900 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E4=BF=A1=E5=90=8D=E3=82=92=E6=9C=AC?= =?UTF-8?q?=E6=96=87=E3=81=AB=E5=90=AB=E3=82=81=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=A6=E3=81=BF=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YouTubeCommentNotifier.user.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/YouTubeCommentNotifier.user.js b/YouTubeCommentNotifier.user.js index 248998c..4f14bc8 100644 --- a/YouTubeCommentNotifier.user.js +++ b/YouTubeCommentNotifier.user.js @@ -51,12 +51,17 @@ const notifySound = { class Message { /** * @param {string} author 投稿者名 + * @param {string} source 投稿のあった配信を表す文字列 * @param {string} iconUrl 投稿者のアイコン * @param {?string} badgeType 投稿者のバッジ * @param {string} body メッセージの本体 */ - constructor(author, iconUrl, badgeType, body) { - Object.assign(this, { author, iconUrl, badgeType, body, }); + constructor(author, source, iconUrl, badgeType, body) { + Object.assign(this, { author, source, iconUrl, badgeType, body, }); + } + + get bodyWithSource() { + return `${this.body}\n\n【${this.source}】`; } /** @@ -98,7 +103,7 @@ class NotifierGM { // GM.notification は、textが空だと通知してくれないんですよね GM.notification({ title: message.author, - text: `${message.body} `, + text: message.bodyWithSource, image: message.iconUrl, }); } @@ -115,7 +120,7 @@ class NotifierGM { class NotifierNotificationAPI { notify(message) { new Notification(message.author, { - body: message.body, + body: message.bodyWithSource, icon: message.iconUrl, }); } @@ -209,12 +214,14 @@ async function main() { if (! chatItemList) return; + const source = window.parent.document.title; + const isEmoji = node => node instanceof Image && node.classList.contains('emoji'); const bodyElemToText = bodyElem => Array.from(bodyElem.childNodes) - .map(e => isEmoji(e) ? e.alt : e.textContent ) + .map(e => isEmoji(e) ? e.alt : e.textContent) .join(''); const toMessage = chatItem => { @@ -228,7 +235,7 @@ async function main() { const body = bodyElemToText(bodyElem); const badgeType = nameElem.getAttribute('type'); - return new Message(name, iconUrl, badgeType, body); + return new Message(name, source, iconUrl, badgeType, body); } };