Facebook
From gregre, 3 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 350
  1. // Function to handle mutations
  2. const handleMutations = (mutationsList, observer) => {
  3.   mutationsList.forEach((mutation) => {
  4.     if (mutation.type === 'childList') {
  5.       mutation.addedNodes.forEach((node) => {
  6.         // Check if the added node is a video element
  7.         if (node.tagName && node.tagName.toLowerCase() === 'video') {
  8.           // Delete the video element
  9.           node.remove();
  10.         }
  11.       });
  12.     }
  13.   });
  14. };
  15.  
  16. // Select the target node
  17. const targetNode = document.body;
  18.  
  19. // Options for the observer (including the types of mutations to observe)
  20. const config = { childList: true, subtree: true };
  21.  
  22. // Create an observer instance linked to the callback function
  23. const observer = new MutationObserver(handleMutations);
  24.  
  25. // Start observing the target node for configured mutations
  26. observer.observe(targetNode, config);
  27.  
  28. // To disconnect the observer later (when you want to stop watching for mutations)
  29. // observer.disconnect();