generated from JohnBra/vite-web-extension
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c19b8f
commit 7e86d00
Showing
10 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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,3 @@ | ||
.yte-hide-translate-comment { | ||
display: none !important; | ||
} |
This file contains 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,27 @@ | ||
import type { Nullable } from "@/src/types"; | ||
|
||
import { observeTranslateComment, translateButtonSelector } from "@/src/features/hideTranslateComment/utils"; | ||
import { modifyElementClassList, waitForAllElements, waitForSpecificMessage } from "@/src/utils/utilities"; | ||
|
||
import "./index.css"; | ||
let translateCommentObserver: Nullable<MutationObserver> = null; | ||
export async function enableHideTranslateComment() { | ||
const { | ||
data: { | ||
options: { enable_hide_translate_comment } | ||
} | ||
} = await waitForSpecificMessage("options", "request_data", "content"); | ||
if (!enable_hide_translate_comment) return; | ||
await waitForAllElements(["ytd-item-section-renderer.ytd-comments div#header div#leading-section"]); | ||
const translateCommentButtons = document.querySelectorAll(translateButtonSelector); | ||
translateCommentButtons.forEach((button) => modifyElementClassList("add", { className: "yte-hide-translate-comment", element: button })); | ||
translateCommentObserver = observeTranslateComment(); | ||
} | ||
|
||
export async function disableHideTranslateComment() { | ||
await waitForAllElements(["ytd-item-section-renderer.ytd-comments div#header div#leading-section"]); | ||
translateCommentObserver?.disconnect(); | ||
translateCommentObserver = null; | ||
const translateCommentButtons = document.querySelectorAll(translateButtonSelector); | ||
translateCommentButtons.forEach((button) => modifyElementClassList("remove", { className: "yte-hide-translate-comment", element: button })); | ||
} |
This file contains 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,26 @@ | ||
import { modifyElementClassList } from "@/src/utils/utilities"; | ||
export const translateButtonSelector = "ytd-tri-state-button-view-model.translate-button"; | ||
|
||
export function observeTranslateComment() { | ||
const observer = new MutationObserver((mutationList) => { | ||
mutationList.forEach((mutation) => { | ||
const translateButtons = Array.from(mutation.addedNodes).some( | ||
(addedNode) => | ||
addedNode instanceof Element && | ||
addedNode.matches("ytd-comment-thread-renderer") && | ||
addedNode.querySelector(translateButtonSelector) !== null | ||
); | ||
if (mutation.type !== "childList" || !mutation.addedNodes.length || !translateButtons) return; | ||
mutation.addedNodes.forEach((addedNode) => { | ||
modifyElementClassList("add", { | ||
className: "yte-hide-translate-comment", | ||
element: (addedNode as Element).querySelector(translateButtonSelector) | ||
}); | ||
}); | ||
}); | ||
}); | ||
const commentsSection = document.querySelector("ytd-item-section-renderer.ytd-comments div#contents"); | ||
if (!commentsSection) return null; | ||
observer.observe(commentsSection, { childList: true, subtree: true }); | ||
return observer; | ||
} |
This file contains 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 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 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 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