From 4042a2acb147d58d26a99aa292cd312ba13b7435 Mon Sep 17 00:00:00 2001 From: ci7lus <7887955+ci7lus@users.noreply.github.com> Date: Fri, 25 Feb 2022 22:51:16 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[saya]=20=E3=82=B3=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=82=BD=E3=83=BC=E3=82=B9=E5=88=A5=E3=81=AB?= =?UTF-8?q?=E3=82=AA=E3=83=9F=E3=83=83=E3=83=88=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=20(#5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/miraktest-saya/comment.ts | 12 +++++++ src/miraktest-saya/index.tsx | 60 +++++++++++++++++++++++++++++++++-- src/miraktest-saya/types.ts | 3 ++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/miraktest-saya/comment.ts b/src/miraktest-saya/comment.ts index 0b932d0..8ae69a4 100644 --- a/src/miraktest-saya/comment.ts +++ b/src/miraktest-saya/comment.ts @@ -6,3 +6,15 @@ export const trimCommentForFlow = (s: string) => { .replace(/^\/nicoad.*/, "") // ニコニ広告削除 .replace(/^\/\w+\s?/, "") // コマンド削除 } + +export const classfySource = (s: string) => { + if (s.startsWith("5ch")) { + return "5ch" + } else if (s.startsWith("Twitter")) { + return "twitter" + } else if (s.startsWith("ニコニコ生放送")) { + return "nicojk" + } else { + return + } +} diff --git a/src/miraktest-saya/index.tsx b/src/miraktest-saya/index.tsx index 4e66a95..968f9b9 100644 --- a/src/miraktest-saya/index.tsx +++ b/src/miraktest-saya/index.tsx @@ -16,7 +16,7 @@ import { DPlayerCommentPayload } from "../miraktest-dplayer/types" import { ChatInput, PECORE_ID } from "../pecore" import { useRefFromState } from "../shared/utils" import tailwind from "../tailwind.scss" -import { trimCommentForFlow } from "./comment" +import { classfySource, trimCommentForFlow } from "./comment" import { SayaSetting } from "./types" /** @@ -31,7 +31,7 @@ const meta = { id: _id, name: "Saya", author: "ci7lus", - version: "0.2.0", + version: "0.2.1", description: "Sayaからコメントを取得するプラグインです。対応するコメントレンダラープラグインが必要です。", } @@ -45,6 +45,9 @@ const main: InitPlugin = { replaces: [], isEnabled: true, isTimeshiftEnabled: true, + isTwitterDisabled: false, + is5chDisabled: false, + isNicojkDisabled: false, }, }) const sayaUrlHistoryAtom = atom({ @@ -194,6 +197,16 @@ const main: InitPlugin = { setRawComment(payload) const commentText = trimCommentForFlow(payload.text) if (commentText.trim().length === 0) return + const source = classfySource(payload.source) + if (sayaSetting.isTwitterDisabled && source === "twitter") { + return + } + if (sayaSetting.is5chDisabled && source === "5ch") { + return + } + if (sayaSetting.isNicojkDisabled && source === "nicojk") { + return + } if (isDplayerFound) { const event = new CustomEvent(DPLAYER_COMMENT_EVENT, { bubbles: false, @@ -270,6 +283,15 @@ const main: InitPlugin = { const [repl2, setRepl2] = useState("") const [sayaHistoryUrl, setSayaHistoryUrl] = useRecoilState(sayaUrlHistoryAtom) + const [is5chDisabled, setIs5chDisabled] = useState( + sayaSetting.is5chDisabled + ) + const [isTwitterDisabled, setIsTwitterDisabled] = useState( + sayaSetting.isTwitterDisabled + ) + const [isNicojkDisabled, setIsNicojkDisabled] = useState( + sayaSetting.isNicojkDisabled + ) return ( <> @@ -294,6 +316,9 @@ const main: InitPlugin = { replaces, isEnabled, isTimeshiftEnabled, + is5chDisabled, + isTwitterDisabled, + isNicojkDisabled, }) }} > @@ -396,6 +421,37 @@ const main: InitPlugin = { + + +