Skip to content

Instantly share code, notes, and snippets.

@neoighodaro
Created October 18, 2022 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neoighodaro/714c432ef15ac65a6362a2ed9efa461e to your computer and use it in GitHub Desktop.
Save neoighodaro/714c432ef15ac65a6362a2ed9efa461e to your computer and use it in GitHub Desktop.
Remove the Signup Modal from Twitter.com when not signed in
// Let you browse Twitter while logged out without being annoyed
// by the scroll-blocking sign up dialog, or the bright blue sign up bottom banner
// We have to observe the entire document for mutations because it's a React app
// Each time a change is detected, we find any of the matching elements to remove/fix
const observer = new MutationObserver(() => {
// Remove blue signUp bar at bottom
const signUpBar = document.querySelector("[data-testid='BottomBar']");
if (signUpBar) signUpBar.remove()
// Find element that contains this text via xpath
const overlayHeaderSpan = document.evaluate('//*[contains(text(), "See more Tweets from")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE).snapshotItem(0) ||
document.evaluate('//*[contains(text(), "See what’s happening")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE).snapshotItem(0);
if (overlayHeaderSpan) {
// Get parent dialog and remove it
const dialog = overlayHeaderSpan.closest("[role='dialog']")
dialog.remove();
// Reset overflow scroll back to normal
document.body.parentElement.style.overflowY = "scroll"
console.log("REMOVED ANNOYING BANNER, SCROLL RESTORED")
}
});
observer.observe(document.body.parentElement, { subtree: true, childList: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment