Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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