Skip to content

Instantly share code, notes, and snippets.

@retrohacker
Last active June 2, 2022 18:19
Show Gist options
  • Save retrohacker/1ea32a6f405c2368992574ee69ffc202 to your computer and use it in GitHub Desktop.
Save retrohacker/1ea32a6f405c2368992574ee69ffc202 to your computer and use it in GitHub Desktop.
Handling dynamic content with greasemonkey
// ==UserScript==
// @name Apply rules to dynamically loaded content
// @version 1
// @grant none
// ==/UserScript==
// Create a new mutation observer
const observer = new window.MutationObserver(() => {
// Apply your rules here
// Example: hide tweet stats on twitter
document.querySelectorAll('div[data-testid="reply"]')
.forEach(v => v.parentElement.parentElement.style["display"] = "none");
});
observer.observe(document, { subtree: true, childList: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment