Skip to content

Commit

Permalink
single button
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencrader committed Oct 24, 2023
1 parent feadfce commit 7e5d7fd
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 7 deletions.
12 changes: 12 additions & 0 deletions .idea/runConfigurations/lint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/lint_fix.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/components/chat-watcher/chat-watcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { consoleLog } from "../../log"
import { checkForMutedWordsChat } from "./muted-words"

let preserveMessageData = true
Expand Down
14 changes: 14 additions & 0 deletions src/components/chat-watcher/muted-words.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ const mutedWordInText = (text: string): boolean => {
return mutedWordRegEx.test(text)
}

/**
* Checks to see if button has already been added to node.
* @param node node to check if parent has a button
* @returns true if button already exists
*/
const hasButton = (node: HTMLElement): boolean => {
const buttonNodes = node.parentElement.querySelectorAll(".show-muted-text-button")
return buttonNodes.length > 0
}

/**
* Add button to show/hide the textNode
* @param textNode The node to show/hide. Button will be added before this node.
Expand All @@ -84,6 +94,10 @@ export const addButtonToggle = (
buttonTextToShow: string = "Show muted text",
buttonTextToHide: string = "Hide muted text",
): void => {
if (hasButton(textNode)) {
return
}

const showButton = document.createElement("button")
showButton.classList.add("show-muted-text-button")
showButton.textContent = buttonTextToShow
Expand Down
1 change: 0 additions & 1 deletion src/components/events/send-action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { consoleLog } from "../../log"
import { Message, Messages } from "../../types/messages"

/**
Expand Down
13 changes: 12 additions & 1 deletion src/components/rants/handler-delete-message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { consoleError } from "../../log"
import { RumbleDeleteNonRantMessages, RumbleEventType } from "../../types/rumble-types"
import { getPreserveMessageData } from "../chat-watcher/chat-watcher"
import { addButtonToggle } from "../chat-watcher/muted-words"

/**
* Delete specified chat
*
Expand All @@ -12,7 +14,16 @@ const deleteMessage = (message_id: string): void => {

messageIds.forEach((chatElement) => {
chatElement.classList.add("deleted-chat")
// TODO: may need to restore text from "data-message"

const savedText = chatElement.getAttribute("data-message")
if (savedText !== "") {
// get the message node
const messageElement: HTMLDivElement = chatElement.querySelector(".chat-history--message")
// add button
addButtonToggle(messageElement, savedText, "Show deleted message", "Hide deleted message")
// replace node with saved text
messageElement.textContent = savedText
}
})
}
/**
Expand Down
5 changes: 2 additions & 3 deletions src/components/rants/handler-mute-user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { consoleError, consoleLog } from "../../log"
import { consoleError } from "../../log"
import { RumbleEventMuteUsers, RumbleEventType } from "../../types/rumble-types"
import { addButtonToggle } from "../chat-watcher/muted-words"

Expand All @@ -13,8 +13,7 @@ const muteUser = (user: string): void => {

userChats.forEach((chatElement) => {
chatElement.classList.add("muted-user")
consoleLog("User muted", user)
// window.alert("Mute user event happened!")

const savedText = chatElement.getAttribute("data-message")
if (savedText !== "") {
// get the message node
Expand Down
5 changes: 4 additions & 1 deletion src/pages/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ <h1>RantStats Extension Options</h1>
<p class="description">
Will mute messages in the chat window and Rant Stats sidebar/popout unless disabled below.
</p>
<p class="note">This only mutes/hides items from displaying. To control words allowed for everyone, edit the settings in Rumble.</p>
<p class="note">
This only mutes/hides items from displaying. To control words allowed for everyone, edit the
settings in Rumble.
</p>
</div>

<div class="selector">
Expand Down

0 comments on commit 7e5d7fd

Please sign in to comment.