Skip to content

Commit

Permalink
配信名を本文に含めるようにしてみた
Browse files Browse the repository at this point in the history
  • Loading branch information
syusui-s committed Jun 23, 2018
1 parent 1f091ab commit 4622d34
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions YouTubeCommentNotifier.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}】`;
}

/**
Expand Down Expand Up @@ -98,7 +103,7 @@ class NotifierGM {
// GM.notification は、textが空だと通知してくれないんですよね
GM.notification({
title: message.author,
text: `${message.body} `,
text: message.bodyWithSource,
image: message.iconUrl,
});
}
Expand All @@ -115,7 +120,7 @@ class NotifierGM {
class NotifierNotificationAPI {
notify(message) {
new Notification(message.author, {
body: message.body,
body: message.bodyWithSource,
icon: message.iconUrl,
});
}
Expand Down Expand Up @@ -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 => {
Expand All @@ -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);
}
};

Expand Down

0 comments on commit 4622d34

Please sign in to comment.