Skip to content

Instantly share code, notes, and snippets.

@angeld23
Last active March 9, 2024 03:23
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save angeld23/b01dd2ef14cd53fc3735fa88f68b7aef to your computer and use it in GitHub Desktop.
Save angeld23/b01dd2ef14cd53fc3735fa88f68b7aef to your computer and use it in GitHub Desktop.
Remove Twitter Blue Promotions: Removes the "Get Verified" box on the Home page and the "Verified" button on the sidebar
// ==UserScript==
// @name Remove Twitter Blue Promotions
// @namespace https://d23.dev/
// @version 1.1
// @description Removes the "Get Verified" box on the Home page and the "Verified" button on the sidebar
// @author angeld23
// @match *://*.twitter.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com
// @grant none
// ==/UserScript==
"use strict";
(() => {
/**
* Calls the provided callback when the document is loaded
*/
function onReady(fn) {
if (document.readyState != "loading") {
fn();
}
else {
document.addEventListener("DOMContentLoaded", fn);
}
}
/**
* Waits for Element added as a descendant of `parent` that matches `selector`.
*/
function waitForElement(parent, selector, callback, runOnce = true) {
const elementNow = parent.querySelector(selector);
if (elementNow) {
callback(elementNow);
if (runOnce) {
return;
}
}
const observer = new MutationObserver((records) => {
records.forEach((record) => {
record.addedNodes.forEach((parentElement) => {
if (parentElement instanceof Element) {
parentElement.querySelectorAll(selector).forEach((element) => {
if (runOnce) {
observer.disconnect();
}
callback(element);
});
}
});
});
});
observer.observe(parent, {
childList: true,
subtree: true,
});
}
onReady(() => {
waitForElement(document, "aside[aria-label='Get Verified']", (element) => {
setTimeout(() => {
element.parentElement?.remove();
}, 100);
}, false);
waitForElement(document, "a[aria-label='Verified'][href='/i/verified-choose']", (element) => {
setTimeout(() => {
element.remove();
}, 100);
}, false);
});
})();
@hl2dmcool
Copy link

You a super player

@angeld23
Copy link
Author

You a super player

Ok now why is this dude so 🅱itHub zaza on the fella upvote?? 😂😂😂 Super su🅱way rizz meme3561672

@angeld23
Copy link
Author

Ahhh! Im a sigma! Super sandwich attack GO!!!!!!!!

@aflacc
Copy link

aflacc commented Jun 11, 2023

ur a real one for this

@kriterin
Copy link

Real

@TeaboyAllStars
Copy link

THANK YOU.

@hexastech
Copy link

THANK YOU.

@carreb
Copy link

carreb commented Jun 11, 2023

THANK YOU.

@ASPJulien
Copy link

Doesn't work for me on firefox 114.0.1 with Windows 11 and tampermonkey :(
image

@angeld23
Copy link
Author

Doesn't work for me on firefox 114.0.1 with Windows 11 and tampermonkey :( image

The way it selects the elements is based off the expected value of the aria-label attribute in English, so with other languages it won't work. You can change the aria-label selectors on line 55 and line 58 to the ones for your language and it should work.

@Glitch3dPenguin
Copy link

Works great! Thank you!

@ASPJulien
Copy link

ASPJulien commented Jun 12, 2023

Doesn't work for me on firefox 114.0.1 with Windows 11 and tampermonkey :( image

The way it selects the elements is based off the expected value of the aria-label attribute in English, so with other languages it won't work. You can change the aria-label selectors on line 55 and line 58 to the ones for your language and it should work.

Thanks you a lot!

@Alumx
Copy link

Alumx commented Jun 12, 2023

Thank you for blessing us 🙏

@skymen
Copy link

skymen commented Jun 12, 2023

/**
     * Calls the provided callback when the document is loaded
     */
    function onReady(fn) {
        if (document.readyState != "loading") {
            fn();
        }
        else {
            document.addEventListener("DOMContentLoaded", fn);
        }
    }
    /**
     * Waits for Element added as a descendant of `parent` that matches `selector`.
     */
    function waitForElement(parent, selector, callback, runOnce = true) {
        const elementNow = parent.querySelector(selector);
        if (elementNow) {
            callback(elementNow);
            if (runOnce) {
                return;
            }
        }
        const observer = new MutationObserver((records) => {
            records.forEach((record) => {
                record.addedNodes.forEach((parentElement) => {
                    if (parentElement instanceof Element) {
                        parentElement.querySelectorAll(selector).forEach((element) => {
                            if (runOnce) {
                                observer.disconnect();
                            }
                            callback(element);
                        });
                    }
                });
            });
        });
        observer.observe(parent, {
            childList: true,
            subtree: true,
        });
    }
    onReady(() => {
        waitForElement(document, "a[href='/i/verified-choose']", (element) => {
            if (element.parentNode && element.parentNode.nodeName.toLowerCase() === 'nav') {
                element.remove();
            } else if (element.parentNode && element.parentNode.parentNode) {
                element.parentNode.parentNode.remove();
            }
        }, false);
    });

This should work without relying on the language of the user. It just detects the href and decides which one it is based on the tag of its parent

@oscoDOTblog
Copy link

gigachad behavior

@Muip1234
Copy link

I've installed this and it's been running flawlessly for the last few days. However, when I went to go onto Twitter today, it wouldn't even load when I had the code running in TamperMonkey. Could this mean Elon's blocked it?

@ASPJulien
Copy link

ASPJulien commented Jun 16, 2023 via email

@skymen
Copy link

skymen commented Jun 16, 2023

It still works fine on my end. I don't see how Elon could block a tampermonkey script 🤔
Does it print an error in the console?
You could also change it's execution start up and put it on context menu and see if it works like that maybe

@BackScratcher107
Copy link

this now breaks the site

@Muip1234
Copy link

I think the reason why it's weird is that there's a new "Communities" tab, which I don't believe was there when this code was made. So maybe something to do with that being added is messing with it, but I'm too tired to look at the code to figure out why. Also, I just love how there's a new tab that gets added to the already clustered sidebar every 5 minutes, and that you'll practically never use it. I also love how it's a shitty, clunky scroll bar instead of literally anything else.
image

@skymen
Copy link

skymen commented Jun 16, 2023

Ah yeah communities tab hasn't appeared for me.

Paste the HTML content of the page on pastebin if you want and I can maybe see what broke

@zerox029
Copy link

I think they might have added a check that blocks the loading of content if the Twitter blue ads aren't there, somewhere in the lifecycle of the website. I got it working again by adding a 400ms timeout before removing the elements. Not ideal but it's better than nothing. It's the only solution I found.

@Trollider76
Copy link

yeah twitter doesn't load when using this extension

@Oinite12
Copy link

Oinite12 commented Jun 18, 2023

The userscript prevents the site from loading, however when I disable the userscript, then load Twitter, then reenable the userscript, Twitter stays up even when browsing through the site, and the userscript still works.

EDIT: nevermind it doesn't work like this for me anymore

@skymen
Copy link

skymen commented Jun 19, 2023

/**
     * Calls the provided callback when the document is loaded
     */
    function onReady(fn) {
        if (document.readyState != "loading") {
            fn();
        }
        else {
            document.addEventListener("DOMContentLoaded", fn);
        }
    }
    /**
     * Waits for Element added as a descendant of `parent` that matches `selector`.
     */
    function waitForElement(parent, selector, callback, runOnce = true) {
        const elementNow = parent.querySelector(selector);
        if (elementNow) {
            callback(elementNow);
            if (runOnce) {
                return;
            }
        }
        const observer = new MutationObserver((records) => {
            records.forEach((record) => {
                record.addedNodes.forEach((parentElement) => {
                    if (parentElement instanceof Element) {
                        parentElement.querySelectorAll(selector).forEach((element) => {
                            if (runOnce) {
                                observer.disconnect();
                            }
                            callback(element);
                        });
                    }
                });
            });
        });
        observer.observe(parent, {
            childList: true,
            subtree: true,
        });
    }
    onReady(() => {
        waitForElement(document, "a[href='/i/verified-choose']", (element) => {
            setTimeout(()=> {
                if (element.parentNode && element.parentNode.nodeName.toLowerCase() === 'nav') {
                    element.remove();
                } else if (element.parentNode && element.parentNode.parentNode) {
                    element.parentNode.parentNode.remove();
                }
            }, 2000);
        }, false);
    });

I finally got the new twitter. It seems like they are detecting if the divs are missing and are starting a infinite loop that lags the page and crashes it.

Anyway, I just added a timeout before removing the element and also, made the script load on document-end instead of document-start

@angeld23
Copy link
Author

angeld23 commented Jul 6, 2023

I went ahead and added a 100ms delay before the element removal which seems to bypass that page-crashing infinite loop some mouthbreather at Twitter added. Let's hope the little lord boy Musky Elon doesn't demand they patch it again

@BombasticMecha
Copy link

Seems they did patch it again, hasn't been working since last night.

@Trimint123
Copy link

Well, it's buffered forever again.

@Glitch3dPenguin
Copy link

It is still not working any longer. 🔢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment