Last active
June 10, 2025 22:56
-
-
Save bartread/11cc72620ed0f7c0b04287de0547c7a6 to your computer and use it in GitHub Desktop.
Who on earth broke CTRL+A on gist?!??
This file contains hidden or 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 Hide tweets from unblockable users using this ViolentMonkey script | |
// @namespace http://arcade.ly/ | |
// @version 1.1.0 | |
// @description Hide tweets from any account you list in UNBLOCKABLE_HANDLES on X (formerly Twitter). Install ViolentMonkey in your browser and then install this script into ViolentMonkey to use. | |
// @author Bart Read | |
// @match https://*.x.com/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
// Add handles (don't include the “@” sign) to the below | |
// array ▼ ▼ ▼ to ensure their tweets are hidden from you. | |
// Make sure you enclose any handles you add within single | |
// quotes, and put a comma after the closing single quote. | |
// To unblock tweets from an account you need to remove | |
// its handle from this list. You can do this by simply | |
// removing it, or by commenting out the line with the | |
// handle on by adding two forward slashes (//) at the | |
// beginning of the line. | |
const UNBLOCKABLE_HANDLES = [ | |
'elonmusk', | |
// 'exampleuser', | |
// 'anotheruser', | |
// 'mr_fart_bag', | |
]; | |
/** | |
* Hides every tweet authored by the given handle. | |
* @param {string} handle – e.g. "elonmusk" | |
*/ | |
function hideTweetsFrom(handle) { | |
const selector = `a[href="/${handle}"], a[href="/${handle}/"]`; | |
const userLinks = document.querySelectorAll(selector); | |
userLinks.forEach(link => { | |
let parentDiv = link; | |
for (let i = 0; i < 11; i++) { | |
if (parentDiv) { | |
parentDiv = parentDiv.parentElement; | |
} | |
} | |
if (parentDiv) { | |
parentDiv.style.display = 'none'; | |
} | |
}); | |
} | |
/** | |
* Hides every tweet authored by handles listed in | |
* UNBLOCKABLE_HANDLES. | |
*/ | |
function hideUnblockableUserTweets() { | |
UNBLOCKABLE_HANDLES.forEach(hideTweetsFrom); | |
} | |
hideUnblockableUserTweets(); | |
const observer = new MutationObserver( | |
hideUnblockableUserTweets | |
); | |
observer.observe(document.body, { | |
childList: true, | |
subtree: true, | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment