Skip to content

Commit

Permalink
✨ [saya] コメントソース別にオミットできるように (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
ci7lus committed Feb 25, 2022
1 parent 7fc529a commit 4042a2a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/miraktest-saya/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
60 changes: 58 additions & 2 deletions src/miraktest-saya/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/**
Expand All @@ -31,7 +31,7 @@ const meta = {
id: _id,
name: "Saya",
author: "ci7lus",
version: "0.2.0",
version: "0.2.1",
description:
"Sayaからコメントを取得するプラグインです。対応するコメントレンダラープラグインが必要です。",
}
Expand All @@ -45,6 +45,9 @@ const main: InitPlugin = {
replaces: [],
isEnabled: true,
isTimeshiftEnabled: true,
isTwitterDisabled: false,
is5chDisabled: false,
isNicojkDisabled: false,
},
})
const sayaUrlHistoryAtom = atom<string[]>({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
<>
<style>{tailwind}</style>
Expand All @@ -294,6 +316,9 @@ const main: InitPlugin = {
replaces,
isEnabled,
isTimeshiftEnabled,
is5chDisabled,
isTwitterDisabled,
isNicojkDisabled,
})
}}
>
Expand Down Expand Up @@ -396,6 +421,37 @@ const main: InitPlugin = {
</button>
</div>
</label>
<label className="block mt-4">
<span>Twitterを除外する</span>
<input
type="checkbox"
className="block mt-2 form-checkbox"
checked={isTwitterDisabled || false}
onChange={() =>
setIsTwitterDisabled((enabled) => !enabled)
}
/>
</label>
<label className="block mt-4">
<span>5chを除外する</span>
<input
type="checkbox"
className="block mt-2 form-checkbox"
checked={is5chDisabled || false}
onChange={() => setIs5chDisabled((enabled) => !enabled)}
/>
</label>
<label className="block mt-4">
<span>ニコニコ実況を除外する</span>
<input
type="checkbox"
className="block mt-2 form-checkbox"
checked={isNicojkDisabled || false}
onChange={() =>
setIsNicojkDisabled((enabled) => !enabled)
}
/>
</label>
<button
type="submit"
className="bg-gray-100 text-gray-800 p-2 px-2 my-4 rounded-md focus:outline-none cursor-pointer"
Expand Down
3 changes: 3 additions & 0 deletions src/miraktest-saya/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ export type SayaSetting = {
replaces: [string, string][]
isEnabled: boolean
isTimeshiftEnabled: boolean
isTwitterDisabled: boolean
is5chDisabled: boolean
isNicojkDisabled: boolean
}

0 comments on commit 4042a2a

Please sign in to comment.