try mutation listener + formatting step

This commit is contained in:
NunoSempere 2023-11-08 23:18:55 +00:00
parent 152445c6d7
commit a7c1f8f57e

View File

@ -89,19 +89,33 @@ if (document.domain == "twitter.com") {
} }
`; `;
document.addEventListener('DOMContentLoaded', function() { // Function to hide the grandparent of video players
// Select all the videoPlayer elements function hideVideoPlayerGrandparent() {
var videoPlayers = document.querySelectorAll('[data-testid="videoPlayer"]'); document
.querySelectorAll('[data-testid="videoPlayer"]')
.forEach(function (videoPlayer) {
var grandparentElement = videoPlayer.parentElement.parentElement;
grandparentElement.style.display = "none";
});
}
// Loop through the NodeList // Create a new MutationObserver instance
videoPlayers.forEach(function(videoPlayer) { var observer = new MutationObserver(function (mutations) {
// Traverse two levels up the DOM tree mutations.forEach(function (mutation) {
var grandparentElement = videoPlayer.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement; if (mutation.addedNodes.length) {
hideVideoPlayerGrandparent(); // Call the function to hide video players
// Hide the grandparent element }
grandparentElement.style.display = 'none';
}); });
}); });
// 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") { if (document.domain == "reddit.com" || document.domain == "old.reddit.com") {