Forked from angeld23/remove_twitter_blue_promo.user.js
Last active
June 12, 2023 09:09
-
-
Save ASPJulien/94242eb1baac9b08d99bea737c74c442 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Remove Twitter Blue Promotions | |
// @namespace https://d23.dev/ | |
// @version 1.0 | |
// @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='Obtenez la certification']", (element) => { | |
element.parentElement?.remove(); | |
}, false); | |
waitForElement(document, "a[aria-label='Certifié'][href='/i/verified-choose']", (element) => { | |
element.remove(); | |
}, false); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment