Skip to content

Instantly share code, notes, and snippets.

@SilverEzhik
Last active October 19, 2018 21:29
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 SilverEzhik/459ac9d92895a6d5c7c777dd6fad68bc to your computer and use it in GitHub Desktop.
Save SilverEzhik/459ac9d92895a6d5c7c777dd6fad68bc to your computer and use it in GitHub Desktop.
Block people on the hell website with one less click
// ==UserScript==
// @name Twitter instant block
// @description Block people on the hell website with one less click
// @include https://twitter.com/*
// @version 1
// @grant none
// ==/UserScript==
// using mozilla sample code
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
// Select the node that will be observed for mutations
var targetNode = document.getElementById("block-dialog"); // so we make an observer to watch the block dialog node
// Options for the observer (which mutations to observe)
var config = {
attributes: true,
childList: true
};
var paused = false;
// Callback function to execute when mutations are observed
var callback = function(mutationsList) {
for (var mutation of mutationsList) {
if (!paused) { // rate limit at least a lil
paused = true;
var block_dialog = document.getElementById("block-dialog"); // will accidentally recurse a lot if targetNode is used
if (block_dialog != null && block_dialog.style.display != "none") { // if the dialog is gonna appear
block_dialog.style.display = "none"; // hide overlay
document.getElementsByClassName("modal-overlay")[0].style.display = "none"; // hide the other background (there are 2 for some reason?)
block_dialog.getElementsByClassName("block-button")[0].click(); // click block button
}
paused = false;
}
}
};
// Create an observer instance linked to the callback function
var observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
// Later, you can stop observing
//observer.disconnect();
@SilverEzhik
Copy link
Author

jam this into greasemonkey or tampermonkey or whatever and enjoy until twitter breaks it

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