aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorNunoSempere <nuno.sempere@protonmail.com>2023-11-08 23:18:55 +0000
committerNunoSempere <nuno.sempere@protonmail.com>2023-11-08 23:18:55 +0000
commita7c1f8f57e90c6071b0285cd2f67a4e4eb2fad9f (patch)
tree5b54e9e93410709ab3ed0316427a7152db62438d /plugins
parent152445c6d7a0743d0210fc29e5989d192b2612fd (diff)
try mutation listener + formatting step
Diffstat (limited to 'plugins')
-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") {