aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/style/style.js36
1 files changed, 25 insertions, 11 deletions
diff --git a/plugins/style/style.js b/plugins/style/style.js
index 46bbc63..0500b7e 100644
--- a/plugins/style/style.js
+++ b/plugins/style/style.js
@@ -89,19 +89,33 @@ if (document.domain == "twitter.com") {
}
`;
- document.addEventListener('DOMContentLoaded', function() {
- // Select all the videoPlayer elements
- var videoPlayers = document.querySelectorAll('[data-testid="videoPlayer"]');
-
- // Loop through the NodeList
- videoPlayers.forEach(function(videoPlayer) {
- // Traverse two levels up the DOM tree
- var grandparentElement = videoPlayer.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
-
- // Hide the grandparent element
- grandparentElement.style.display = 'none';
+ // Function to hide the grandparent of video players
+ function hideVideoPlayerGrandparent() {
+ document
+ .querySelectorAll('[data-testid="videoPlayer"]')
+ .forEach(function (videoPlayer) {
+ var grandparentElement = videoPlayer.parentElement.parentElement;
+ grandparentElement.style.display = "none";
+ });
+ }
+
+ // Create a new MutationObserver instance
+ var observer = new MutationObserver(function (mutations) {
+ mutations.forEach(function (mutation) {
+ if (mutation.addedNodes.length) {
+ hideVideoPlayerGrandparent(); // Call the function to hide video players
+ }
});
});
+
+ // Options for the observer (which mutations to observe)
+ var config = { childList: true, subtree: true };
+
+ // Start observing the target node for configured mutations
+ observer.observe(document.body, config);
+
+ // Call the function initially to hide any video players on initial load
+ hideVideoPlayerGrandparent();
}
if (document.domain == "reddit.com" || document.domain == "old.reddit.com") {