Last active
November 25, 2018 01:51
-
-
Save SilverEzhik/618cf569e9ed44c291bf2fbd9d01ea9f to your computer and use it in GitHub Desktop.
Block people on the lite version of the hell website with one less click
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 Twitter Lite instant block | |
// @description Block people on the hell website with one less click | |
// @include https://mobile.twitter.com/* | |
// @version 1 | |
// @grant none | |
// @run-at document-idle | |
// ==/UserScript== | |
// using mozilla sample code | |
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver | |
// Text to check for in the message - change this to fit your twitter language! | |
var blockText = "will not be able to follow you or view your Tweets, and you will not see Tweets or notifications from"; | |
async function sleep(ms = 0) { | |
return new Promise(r => setTimeout(r, ms)); | |
} | |
// Select the node that will be observed for mutations | |
//var targetNode; | |
async function go() { | |
while (document.getElementsByTagName("main").length == 0) { | |
await sleep(500); | |
} | |
var targetNode = document.getElementsByTagName("main")[0].parentNode; // watch the tweet container, actually. | |
// Options for the observer (which mutations to observe) | |
var config = { | |
attributes: true, | |
childList: false, | |
subtree: false, | |
attributeFilter: ["aria-hidden"] | |
}; | |
var paused = false; | |
// Callback function to execute when mutations are observed | |
var callback = function(mutationsList) { | |
for (var mutation of mutationsList) { | |
//console.log(mutation); | |
if (!paused) { // rate limit at least a lil | |
paused = true; | |
var node = document.querySelector('[data-testid="confirmationSheetConfirm"]'); // will accidentally recurse a lot if targetNode is used | |
if (node != null && node.parentNode.innerHTML.includes(blockText)) { // if the dialog is gonna appear | |
node.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(); | |
} | |
go(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment