Skip to content

Instantly share code, notes, and snippets.

@mousavian
Created November 10, 2022 08:29
Show Gist options
  • Save mousavian/3d6868f9ef6093c116bf9afc31d63491 to your computer and use it in GitHub Desktop.
Save mousavian/3d6868f9ef6093c116bf9afc31d63491 to your computer and use it in GitHub Desktop.
Twitter Ato report using Tamperbmonkey
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://twitter.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com
// @grant none
// ==/UserScript==
let d = document;
let default_wait=450;
(function() {
'use strict';
document.addEventListener('load', load_blocker);
document.addEventListener('scroll', load_blocker);
new PerformanceObserver(load_blocker).observe({type: 'largest-contentful-paint', buffered: true});
})();
function _spam({art, el, dialog}){
//let dims = art.getBoundingClientRect();
//window.scrollTo(window.scrollX, dims.top -250);
art.style.border = 'thick dotted red';
setTimeout(()=>{
clickOnItem(dialog, 'Everyone on Twitter')
clickNext(dialog)
setTimeout(()=>{
clickOnItem(dialog, 'repetitive replies')
clickNext(dialog)
setTimeout(()=>{
clickOnItem(dialog, 'Sending a lot of aggressive, unwanted, repetitive or unrelated replies, Retweets, or Direct Messages')
clickNext(dialog)
setTimeout(()=>{
dialog.querySelector('[data-testid=ocfSettingsListNextButton]').click()
setTimeout(()=>{
dialog.querySelector('[data-testid=ocfSettingsListNextButton]').click()
setTimeout(()=>{
dialog.querySelector('[data-testid=ocfSettingsListNextButton]').click()
art.style.border = '0px';
el.checked=false;el.disabled="disabled";
art.dataset.reported=true;
setTimeout(startReporting(_spam), default_wait)
}, default_wait)
}, default_wait)
}, default_wait)
}, default_wait)
}, default_wait)
}, default_wait)
}
function _viol({art, el, dialog:dg}){
//let dims = art.getBoundingClientRect();
//window.scrollTo(window.scrollX, dims.top -250);
scrollTo(art)
art.style.border = 'thick dotted red';
setTimeout(()=>{
dg.querySelector('input[aria-posinset="2"]').parentElement.click()
dg.querySelector('[data-testid=ChoiceSelectionNextButton]').click()
console.log('Someone else or a specific group of people')
setTimeout(()=>{
dg.querySelector('input[aria-posinset="2"]').parentElement.click()
dg.querySelector('[data-testid=ChoiceSelectionNextButton]').click()
console.log('Harassed or intimidated with violence')
setTimeout(()=>{
dg.querySelector('input[aria-posinset="10"]').parentElement.click()
dg.querySelector('[data-testid=ChoiceSelectionNextButton]').click()
console.log('Threatening them with violence')
setTimeout(()=>{
Array.from(dg.getElementsByTagName('span')).find(e=>e.getInnerHTML().includes('Race, ethnicity, caste, or national origin')).click()
Array.from(dg.getElementsByTagName('span')).find(e=>e.getInnerHTML().includes('Religion')).click()
Array.from(dg.getElementsByTagName('span')).find(e=>e.getInnerHTML().includes('Gender/gender identity')).click()
dg.querySelector('[data-testid=ChoiceSelectionNextButton]').click()
console.log('because of')
setTimeout(()=>{
dg.querySelector('[data-testid=ocfSettingsListNextButton]').click()
console.log('yup1')
setTimeout(()=>{
dg.querySelector('[data-testid=ocfSettingsListNextButton]').click()
console.log('yup2')
setTimeout(()=>{
dg.querySelector('[data-testid=ocfSettingsListNextButton]').click()
console.log('"' +(art.querySelector('[data-testid=User-Names]').innerText.replace('\n', '\\'))+ '" is done; heading to the next one...')
art.style.border = '0px';
art.dataset.reported=true;
el.checked=false;el.disabled="disabled";
setTimeout(startReporting(_viol), default_wait)
}, default_wait)
}, default_wait)
}, default_wait)
}, 700)
}, default_wait)
}, default_wait)
}, default_wait)
}
function startReporting(next){
return () => {
let els = document.querySelectorAll('.k0fPBblocker_checkbox:checked');
console.log("Processing " + (els.length) + " tweets")
if (els.length ==0) return;
let el = els[0];
let art = el.closest('article')
let caret = art.querySelector('[data-testid=caret]')
caret.click();
console.log('Begin:' + art.querySelector('[data-testid=User-Names]').innerText.replace('\n', '\\'))
scrollTo(art)
art.style.border = 'thick dotted red';
document.querySelector('[data-testid=report]').click()
setTimeout(()=>{
let dialog = document.querySelector('[data-testid="OCF_CallToAction_Button"]').closest('[role=dialog]')
document.querySelector('[data-testid=OCF_CallToAction_Button]').click();
console.log('reporting started...')
next({art, el, dialog})
}, default_wait)
};
}
function add_btns(d){
let _s='width: 100px;height: 50px;'
let dd = d.createElement('div'); let br = ()=>d.createElement('br');
let btn1 = d.createElement('button'); btn1.innerHTML='Start'; btn1.style=_s; btn1.id = 'k0fPBblocker_startbtn';
let btn2 = d.createElement('button'); btn2.innerHTML='-> Violence'; btn2.style=_s;
let btn3 = d.createElement('button'); btn3.innerHTML='-> Spam'; btn3.style=_s;
dd.appendChild(btn1);dd.appendChild(br());dd.appendChild(btn2);dd.appendChild(br());dd.appendChild(btn3);
dd.style='position: fixed; top:0; right:0;';
d.body.appendChild(dd);
btn1.addEventListener('click', initReporting);
btn2.addEventListener('click', startReporting(_viol));
btn3.addEventListener('click', startReporting(_spam));
}
function initReporting(){
const getdivbox = () => {
let r=d.createElement('div');
r.style = 'text-align: center;padding: 20px 0;';
r.innerHTML = '<input type="checkbox" style="width: 50px;height: 50px;" class="k0fPBblocker_checkbox">';
return r.outerHTML;
}
let twArticle = Array.from(d.querySelectorAll('article')).filter(function(art) {
return art.dataset.testid == 'tweet' && art.dataset.hasBlockerbox != '1';
})
Array.from(twArticle, art => {
art.dataset.hasBlockerbox = '1'
art.querySelector('[data-testid=Tweet-User-Avatar]').innerHTML += getdivbox();
})
console.log('tweets: ', twArticle.length)
}
function load_blocker(){
if (d.getElementById('k0fPBblocker_startbtn') == null){ add_btns(d) }
}
function scrollTo(art){
window.scrollTo(window.scrollX, window.scrollY + (art.getBoundingClientRect().top - 55))
}
function clickOnItem(dialog, txt){
console.log('Clicking on:' + txt)
Array.from(dialog.querySelectorAll('span')).find(e=>e.innerText.includes(txt)).click()
}
function clickNext(dialog){
console.log('Next...')
dialog.querySelector('[data-testid=ChoiceSelectionNextButton]').click()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment