Skip to content

Instantly share code, notes, and snippets.

@absindx
Last active February 5, 2023 08:41
Show Gist options
  • Save absindx/b87304860e3fa72c441a240294e346f4 to your computer and use it in GitHub Desktop.
Save absindx/b87304860e3fa72c441a240294e346f4 to your computer and use it in GitHub Desktop.
Removed the dialog when not logged in.
// ==UserScript==
// @name Twitter is SHIT
// @version 20221001
// @description Twitter can't be Instagram
// @match https://twitter.com/*
// ==/UserScript==
(function() {
'use strict';
function revertScroll(){
const elements = document.getElementsByTagName('html');
for(let i = 0; i < elements.length; i++){
elements[i].style.removeProperty('overflow');
}
}
function removeDialog(){
const elements = document.getElementsByTagName('div');
const searchAttributeName = 'data-testid';
const searchAttributeValue = 'sheetDialog';
for(let i = 0; i < elements.length; i++){
const element = elements[i];
const searchAttr = element.getAttribute(searchAttributeName);
if(searchAttr === searchAttributeValue){
element.parentElement.parentElement.removeChild(element.parentElement);
removeDialog();
break;
}
}
}
function removeContentWarning(){
// <article data-testid="tweet">
const articles = document.getElementsByTagName('article');
const searchAttributeName = 'data-testid';
const searchAttributeValue = 'tweet';
let tweetArticles = [];
for(let i = 0; i < articles.length; i++){
if(articles[i].getAttribute(searchAttributeName) === searchAttributeValue){
tweetArticles.push(articles[i]);
}
}
for(let i = 0; i < tweetArticles.length; i++){
// timeline
try{
const mediaContainer = tweetArticles[i].children[0].children[0].children[0].children[1].children[1].children[1] // tweet body
.children[1] // media
.children[0].children[0].children[0]; // wrapper
// remove content warning
mediaContainer.removeChild(mediaContainer.children[1]);
// remove blur
mediaContainer.children[0].style.filter = 'blur(0px)';
}
catch{}
// tweet detail page
try{
const mediaContainer = tweetArticles[i].children[0].children[0].children[0].children[2] // tweet body
.children[2] // media
.children[0].children[0].children[0].children[0]; // wrapper
// remove content warning
mediaContainer.removeChild(mediaContainer.children[1]);
// remove blur
mediaContainer.children[0].style.filter = 'blur(0px)';
}
catch{}
}
}
function tick(){
revertScroll();
removeDialog();
removeContentWarning();
}
setInterval(tick, 500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment