Skip to content

Instantly share code, notes, and snippets.

@kms70847
Created October 29, 2021 14:21
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 kms70847/159d041465b793f86c8b7777091c963d to your computer and use it in GitHub Desktop.
Save kms70847/159d041465b793f86c8b7777091c963d to your computer and use it in GitHub Desktop.
Remove Signup Bar From Twitter
// ==UserScript==
// @name Remove Signup Bar
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Remove the "sign up for twitter!" bar that blocks 20% of the content on every Twitter page
// @author Kevin
// @match https://twitter.com/*
// @icon https://www.google.com/s2/favicons?domain=twitter.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const signupSelector = "[data-testid=signup]";
const followSelector = "[aria-label^='Follow']";
//distance between a node and the root.
function height(node){
let x = 0;
while(node.parentNode != null){
node = node.parentNode;
x += 1;
}
return x;
}
//lowest node in the tree that is the ancestor of both arguments.
function lowest_common_ancestor(a,b){
let a_height = height(a);
let b_height = height(b);
while (a_height > b_height){
a = a.parentNode;
a_height -= 1;
}
while (b_height > a_height){
b = b.parentNode;
b_height -= 1;
}
while (a != b){
a = a.parentNode;
b = b.parentNode;
}
return a;
}
//like removeChild, but removes every node between ancestor and descendant
function removeLineage(ancestor, descendant){
while(descendant.parentNode != ancestor){
descendant = descendant.parentNode;
}
ancestor.removeChild(descendant);
}
//Deletes the largest possible branch of the DOM that erases nodeToRemove without erasing nodeToKeep.
function prune(nodeToRemove, nodeToKeep){
let ancestor = lowest_common_ancestor(nodeToRemove, nodeToKeep);
removeLineage(ancestor, nodeToRemove);
}
//call `callback` shortly after an element matching `selector` is added to the DOM.
function onExists(selector, callback){
let node = document.querySelector(selector);
if (node != null){
callback(node);
}
else{
setTimeout(onExists, 100, selector, callback);
}
}
onExists(signupSelector, function(signupButton){
//console.log("found Signup button.");
onExists(followSelector, function(followButton){
//console.log("found follow button.");
prune(signupButton, followButton);
});
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment