Skip to content

Instantly share code, notes, and snippets.

@alkimiadev
Created September 23, 2025 22:44
Show Gist options
  • Save alkimiadev/a890b32d5ff6e6ed143b05f83c90fd38 to your computer and use it in GitHub Desktop.
Save alkimiadev/a890b32d5ff6e6ed143b05f83c90fd38 to your computer and use it in GitHub Desktop.
tamper monkey script to block all users who reply to a tweet(starting at index 4 for my specific use case)
// ==UserScript==
// @name Block Tweet Responders
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Blocks all users who replied to a tweet starting from the 5th reply
// @author me
// @match https://x.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Function to add a delay between actions
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Function to block tweet responders
async function blockTweetResponders() {
// Find all tweet elements
const tweets = document.querySelectorAll('[data-testid="tweet"]');
// Start from the 5th tweet (index 4)
for (let i = 4; i < tweets.length; i++) {
const tweet = tweets[i];
try {
// Find and click the "More" button
const moreButton = tweet.querySelector('[data-testid="caret"]');
if (moreButton) {
moreButton.click();
await sleep(500); // Wait for the menu to appear
// Find and click the "Block" option
const blockButton = Array.from(document.querySelectorAll('span'))
.find(span => span.textContent && span.textContent.includes('Block @'));
if (blockButton) {
blockButton.click();
await sleep(500); // Wait for the confirmation dialog
// Confirm the block if there's a confirmation button
const confirmButton = Array.from(document.querySelectorAll('span'))
.find(span => span.textContent && span.textContent.includes('Block'));
if (confirmButton) {
confirmButton.click();
await sleep(1000); // Wait for the block to complete
}
}
}
} catch (error) {
console.error('Error blocking tweet:', error);
}
}
}
// Create a button to trigger the blocking
const blockButton = document.createElement('button');
blockButton.textContent = 'Block Tweet Responders';
blockButton.style.position = 'fixed';
blockButton.style.top = '10px';
blockButton.style.right = '10px';
blockButton.style.zIndex = '9999';
blockButton.style.padding = '10px';
blockButton.style.backgroundColor = '#1DA1F2';
blockButton.style.color = 'white';
blockButton.style.border = 'none';
blockButton.style.borderRadius = '5px';
blockButton.style.cursor = 'pointer';
blockButton.style.fontWeight = 'bold';
blockButton.addEventListener('click', blockTweetResponders);
document.body.appendChild(blockButton);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment