-
Notifications
You must be signed in to change notification settings - Fork 21
Implement chat monitor for cross-platform keyword detection with shared storage #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
11
commits into
master
Choose a base branch
from
copilot/add-chat-monitor-feature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fe2abc7
Initial plan
Copilot 849dcff
Add chat monitor types, services, and background integration
Copilot 64416ea
Fix husky hooks for bun PATH
Copilot 5dabc8a
Add chat monitor settings UI for both platforms
Copilot cca297a
Add chat monitor UI components and integrate with platforms
Copilot ddc5429
Refactor chat monitor to use shared storage and add silent ping support
Copilot 2008585
Refactor to use proper shared storage pattern with getSharedStorageDa…
Copilot 6778295
Fix chrome.runtime access in content scripts - use worker bridge for …
Copilot d8fc45f
Add SharedStorageService with typed utility functions for cleaner access
Copilot 110d55c
fix twitch connector
igorovh f1dcfb6
Merge branch 'master' into copilot/add-chat-monitor-feature
igorovh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
src/platforms/kick/modules/chat-monitor-button/chat-monitor-button.module.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import { ChatMonitorPingMenu } from "$shared/components/chat-monitor-ping/chat-monitor-ping-menu.component.tsx"; | ||
| import { TooltipComponent } from "$shared/components/tooltip/tooltip.component.tsx"; | ||
| import type { KickModuleConfig } from "$types/shared/module/module.types.ts"; | ||
| import { render } from "preact"; | ||
| import { useState } from "preact/hooks"; | ||
| import styled from "styled-components"; | ||
| import KickModule from "../../kick.module.ts"; | ||
|
|
||
| export default class ChatMonitorButtonModule extends KickModule { | ||
| readonly config: KickModuleConfig = { | ||
| name: "chat-monitor-button", | ||
| appliers: [ | ||
| { | ||
| type: "selector", | ||
| selectors: ["#header-primary-menu"], | ||
| callback: this.run.bind(this), | ||
| key: "chat-monitor-button-main", | ||
| once: true, | ||
| }, | ||
| { | ||
| type: "event", | ||
| event: "extension:chat-monitor-open", | ||
| callback: this.openChatMonitor.bind(this), | ||
| key: "chat-monitor-open", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| private menuContainer: HTMLDivElement | null = null; | ||
|
|
||
| private async run(elements: Element[], key: string) { | ||
| const wrappers = this.commonUtils().createEmptyElements(this.getId(), elements, "div"); | ||
| const logo = await this.commonUtils().getAssetFile(this.workerService(), "enhancer/logo-gray.svg"); | ||
|
|
||
| wrappers.forEach((element) => { | ||
| render( | ||
| <TooltipComponent content={<p>Open Chat Monitor</p>} position="bottom"> | ||
| <ChatMonitorButtonComponent onClick={this.openChatMonitor.bind(this)} logoUrl={logo} /> | ||
| </TooltipComponent>, | ||
| element, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| private openChatMonitor() { | ||
| // Create menu container if it doesn't exist | ||
| if (!this.menuContainer) { | ||
| this.menuContainer = document.createElement("div"); | ||
| this.menuContainer.id = `${this.getId()}-menu-container`; | ||
| document.body.appendChild(this.menuContainer); | ||
| } | ||
|
|
||
| // Render the menu | ||
| render( | ||
| <ChatMonitorPingMenu workerService={this.workerService()} onClose={this.closeChatMonitor.bind(this)} />, | ||
| this.menuContainer, | ||
| ); | ||
| } | ||
|
|
||
| private closeChatMonitor() { | ||
| if (this.menuContainer) { | ||
| render(null, this.menuContainer); | ||
| } | ||
| } | ||
|
|
||
| async initialize() { | ||
| this.commonUtils().createGlobalStyle(` | ||
| #header-primary-menu .enhancer-chat-monitor-button { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
| `); | ||
|
|
||
| // Listen for keyword match events from background via worker service | ||
| this.workerService().onBackgroundMessage((message) => { | ||
| if (message.action === "chatMonitorPing") { | ||
| // Show notification or update badge | ||
| this.showNotificationBadge(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private showNotificationBadge() { | ||
| // Add a visual indicator that there's a new match | ||
| const buttons = document.querySelectorAll(".enhancer-chat-monitor-button button"); | ||
| for (const button of buttons) { | ||
| button.classList.add("has-notification"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const StyledChatMonitorButton = styled.button` | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| border-radius: 8px; | ||
| width: 36px; | ||
| height: 36px; | ||
| cursor: pointer; | ||
| position: relative; | ||
|
|
||
| border: none; | ||
| background: transparent; | ||
| padding: 0; | ||
| color: inherit; | ||
|
|
||
| &:hover { | ||
| background: rgba(255, 255, 255, 0.1); | ||
| } | ||
|
|
||
| &:focus-visible { | ||
| outline: 2px solid var(--color-focus, #007bff); | ||
| outline-offset: 2px; | ||
| } | ||
|
|
||
| &.has-notification::after { | ||
| content: ""; | ||
| position: absolute; | ||
| top: 6px; | ||
| right: 6px; | ||
| width: 8px; | ||
| height: 8px; | ||
| background: #53fc18; | ||
| border-radius: 50%; | ||
| border: 2px solid #000; | ||
| } | ||
|
|
||
| img { | ||
| width: 24px; | ||
| height: 24px; | ||
| filter: brightness(0) invert(0.5); | ||
| } | ||
|
|
||
| &:hover img { | ||
| filter: brightness(0) invert(0.7); | ||
| } | ||
| `; | ||
|
|
||
| interface ChatMonitorButtonComponentProps { | ||
| onClick: () => void; | ||
| logoUrl: string; | ||
| } | ||
|
|
||
| function ChatMonitorButtonComponent({ onClick, logoUrl }: ChatMonitorButtonComponentProps) { | ||
| const [hasNotification] = useState(false); | ||
|
|
||
| return ( | ||
| <StyledChatMonitorButton onClick={onClick} className={hasNotification ? "has-notification" : ""}> | ||
| <img src={logoUrl} alt={"Chat Monitor"} /> | ||
| </StyledChatMonitorButton> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
src/platforms/twitch/modules/chat-monitor-button/chat-monitor-button.module.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import { ChatMonitorPingMenu } from "$shared/components/chat-monitor-ping/chat-monitor-ping-menu.component.tsx"; | ||
| import { TooltipComponent } from "$shared/components/tooltip/tooltip.component.tsx"; | ||
| import type { TwitchModuleConfig } from "$types/shared/module/module.types.ts"; | ||
| import { render } from "preact"; | ||
| import { useState } from "preact/hooks"; | ||
| import styled from "styled-components"; | ||
| import TwitchModule from "../../twitch.module.ts"; | ||
|
|
||
| export default class ChatMonitorButtonModule extends TwitchModule { | ||
| readonly config: TwitchModuleConfig = { | ||
| name: "chat-monitor-button", | ||
| appliers: [ | ||
| { | ||
| type: "selector", | ||
| selectors: [".top-nav__menu"], | ||
| callback: this.run.bind(this), | ||
| key: "chat-monitor-button-main", | ||
| once: true, | ||
| }, | ||
| { | ||
| type: "event", | ||
| event: "extension:chat-monitor-open", | ||
| callback: this.openChatMonitor.bind(this), | ||
| key: "chat-monitor-open", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| private menuContainer: HTMLDivElement | null = null; | ||
|
|
||
| private async run(elements: Element[], key: string) { | ||
| const properElements = elements | ||
| .filter((element) => element.children.length > 0) | ||
| .map((element) => [...element.children].at(-1)) | ||
| .filter((element) => element !== undefined) as Element[]; | ||
| const wrappers = this.commonUtils().createEmptyElements(this.getId(), properElements, "span"); | ||
| const logo = await this.commonUtils().getAssetFile(this.workerService(), "enhancer/logo-gray.svg"); | ||
|
|
||
| wrappers.forEach((element) => { | ||
| render( | ||
| <TooltipComponent content={<p>Open Chat Monitor</p>} position="bottom"> | ||
| <ChatMonitorButtonComponent onClick={this.openChatMonitor.bind(this)} logoUrl={logo} /> | ||
| </TooltipComponent>, | ||
| element, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| private openChatMonitor() { | ||
| // Create menu container if it doesn't exist | ||
| if (!this.menuContainer) { | ||
| this.menuContainer = document.createElement("div"); | ||
| this.menuContainer.id = `${this.getId()}-menu-container`; | ||
| document.body.appendChild(this.menuContainer); | ||
| } | ||
|
|
||
| // Render the menu | ||
| render( | ||
| <ChatMonitorPingMenu workerService={this.workerService()} onClose={this.closeChatMonitor.bind(this)} />, | ||
| this.menuContainer, | ||
| ); | ||
| } | ||
|
|
||
| private closeChatMonitor() { | ||
| if (this.menuContainer) { | ||
| render(null, this.menuContainer); | ||
| } | ||
| } | ||
|
|
||
| async initialize() { | ||
| this.commonUtils().createGlobalStyle(` | ||
| .top-nav__menu .enhancer-chat-monitor-button { order: -6 !important; } | ||
| `); | ||
|
|
||
| // Listen for keyword match events from background via worker service | ||
| this.workerService().onBackgroundMessage((message) => { | ||
| if (message.action === "chatMonitorPing") { | ||
| // Show notification or update badge | ||
| this.showNotificationBadge(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private showNotificationBadge() { | ||
| // Add a visual indicator that there's a new match | ||
| const buttons = document.querySelectorAll(".enhancer-chat-monitor-button button"); | ||
| for (const button of buttons) { | ||
| button.classList.add("has-notification"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const StyledChatMonitorButton = styled.button` | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| border-radius: var(--border-radius-medium); | ||
| width: 30px; | ||
| height: 30px; | ||
| cursor: pointer; | ||
| position: relative; | ||
| margin-top: 4px; | ||
|
|
||
| border: none; | ||
| background: transparent; | ||
| padding: 0; | ||
| color: inherit; | ||
|
|
||
| &:hover { | ||
| background: var(--color-background-button-text-hover); | ||
| } | ||
|
|
||
| &:focus-visible { | ||
| outline: 2px solid var(--color-focus, #007bff); | ||
| outline-offset: 2px; | ||
| } | ||
|
|
||
| &.has-notification::after { | ||
| content: ""; | ||
| position: absolute; | ||
| top: 6px; | ||
| right: 6px; | ||
| width: 8px; | ||
| height: 8px; | ||
| background: #9147ff; | ||
| border-radius: 50%; | ||
| border: 2px solid #0d0d0d; | ||
| } | ||
|
|
||
| img { | ||
| filter: brightness(0) invert(0.5); | ||
| } | ||
|
|
||
| &:hover img { | ||
| filter: brightness(0) invert(0.7); | ||
| } | ||
| `; | ||
|
|
||
| interface ChatMonitorButtonComponentProps { | ||
| onClick: () => void; | ||
| logoUrl: string; | ||
| } | ||
|
|
||
| function ChatMonitorButtonComponent({ onClick, logoUrl }: ChatMonitorButtonComponentProps) { | ||
| const [hasNotification] = useState(false); | ||
|
|
||
| return ( | ||
| <StyledChatMonitorButton onClick={onClick} className={hasNotification ? "has-notification" : ""}> | ||
| <img src={logoUrl} alt={"Chat Monitor"} /> | ||
| </StyledChatMonitorButton> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe move it to the settings-button module and rename this module to navbar-icons-module wdyt, we could also seperate logic in files in this module direcotry for settings and chat monitor