Skip to content

Commit 4042a2a

Browse files
committed
✨ [saya] コメントソース別にオミットできるように (#5)
1 parent 7fc529a commit 4042a2a

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

src/miraktest-saya/comment.ts

+12
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@ export const trimCommentForFlow = (s: string) => {
66
.replace(/^\/nicoad.*/, "") // ニコニ広告削除
77
.replace(/^\/\w+\s?/, "") // コマンド削除
88
}
9+
10+
export const classfySource = (s: string) => {
11+
if (s.startsWith("5ch")) {
12+
return "5ch"
13+
} else if (s.startsWith("Twitter")) {
14+
return "twitter"
15+
} else if (s.startsWith("ニコニコ生放送")) {
16+
return "nicojk"
17+
} else {
18+
return
19+
}
20+
}

src/miraktest-saya/index.tsx

+58-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { DPlayerCommentPayload } from "../miraktest-dplayer/types"
1616
import { ChatInput, PECORE_ID } from "../pecore"
1717
import { useRefFromState } from "../shared/utils"
1818
import tailwind from "../tailwind.scss"
19-
import { trimCommentForFlow } from "./comment"
19+
import { classfySource, trimCommentForFlow } from "./comment"
2020
import { SayaSetting } from "./types"
2121

2222
/**
@@ -31,7 +31,7 @@ const meta = {
3131
id: _id,
3232
name: "Saya",
3333
author: "ci7lus",
34-
version: "0.2.0",
34+
version: "0.2.1",
3535
description:
3636
"Sayaからコメントを取得するプラグインです。対応するコメントレンダラープラグインが必要です。",
3737
}
@@ -45,6 +45,9 @@ const main: InitPlugin = {
4545
replaces: [],
4646
isEnabled: true,
4747
isTimeshiftEnabled: true,
48+
isTwitterDisabled: false,
49+
is5chDisabled: false,
50+
isNicojkDisabled: false,
4851
},
4952
})
5053
const sayaUrlHistoryAtom = atom<string[]>({
@@ -194,6 +197,16 @@ const main: InitPlugin = {
194197
setRawComment(payload)
195198
const commentText = trimCommentForFlow(payload.text)
196199
if (commentText.trim().length === 0) return
200+
const source = classfySource(payload.source)
201+
if (sayaSetting.isTwitterDisabled && source === "twitter") {
202+
return
203+
}
204+
if (sayaSetting.is5chDisabled && source === "5ch") {
205+
return
206+
}
207+
if (sayaSetting.isNicojkDisabled && source === "nicojk") {
208+
return
209+
}
197210
if (isDplayerFound) {
198211
const event = new CustomEvent(DPLAYER_COMMENT_EVENT, {
199212
bubbles: false,
@@ -270,6 +283,15 @@ const main: InitPlugin = {
270283
const [repl2, setRepl2] = useState("")
271284
const [sayaHistoryUrl, setSayaHistoryUrl] =
272285
useRecoilState(sayaUrlHistoryAtom)
286+
const [is5chDisabled, setIs5chDisabled] = useState(
287+
sayaSetting.is5chDisabled
288+
)
289+
const [isTwitterDisabled, setIsTwitterDisabled] = useState(
290+
sayaSetting.isTwitterDisabled
291+
)
292+
const [isNicojkDisabled, setIsNicojkDisabled] = useState(
293+
sayaSetting.isNicojkDisabled
294+
)
273295
return (
274296
<>
275297
<style>{tailwind}</style>
@@ -294,6 +316,9 @@ const main: InitPlugin = {
294316
replaces,
295317
isEnabled,
296318
isTimeshiftEnabled,
319+
is5chDisabled,
320+
isTwitterDisabled,
321+
isNicojkDisabled,
297322
})
298323
}}
299324
>
@@ -396,6 +421,37 @@ const main: InitPlugin = {
396421
</button>
397422
</div>
398423
</label>
424+
<label className="block mt-4">
425+
<span>Twitterを除外する</span>
426+
<input
427+
type="checkbox"
428+
className="block mt-2 form-checkbox"
429+
checked={isTwitterDisabled || false}
430+
onChange={() =>
431+
setIsTwitterDisabled((enabled) => !enabled)
432+
}
433+
/>
434+
</label>
435+
<label className="block mt-4">
436+
<span>5chを除外する</span>
437+
<input
438+
type="checkbox"
439+
className="block mt-2 form-checkbox"
440+
checked={is5chDisabled || false}
441+
onChange={() => setIs5chDisabled((enabled) => !enabled)}
442+
/>
443+
</label>
444+
<label className="block mt-4">
445+
<span>ニコニコ実況を除外する</span>
446+
<input
447+
type="checkbox"
448+
className="block mt-2 form-checkbox"
449+
checked={isNicojkDisabled || false}
450+
onChange={() =>
451+
setIsNicojkDisabled((enabled) => !enabled)
452+
}
453+
/>
454+
</label>
399455
<button
400456
type="submit"
401457
className="bg-gray-100 text-gray-800 p-2 px-2 my-4 rounded-md focus:outline-none cursor-pointer"

src/miraktest-saya/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ export type SayaSetting = {
33
replaces: [string, string][]
44
isEnabled: boolean
55
isTimeshiftEnabled: boolean
6+
isTwitterDisabled: boolean
7+
is5chDisabled: boolean
8+
isNicojkDisabled: boolean
69
}

0 commit comments

Comments
 (0)