Skip to content

Instantly share code, notes, and snippets.

@juzybits
Forked from banteg/twitter-report.js
Last active September 10, 2023 03:50
Show Gist options
  • Select an option

  • Save juzybits/331656caff9296027b1f4e035ca7be09 to your computer and use it in GitHub Desktop.

Select an option

Save juzybits/331656caff9296027b1f4e035ca7be09 to your computer and use it in GitHub Desktop.
report tweet as spam and block its author
/*
A script to report a tweet as spam and block its author.
It is meant to be run from the browser console.
How to use:
1) On Twitter, click "Report post"
2) Copy-paste this script into the console
*/
function waitForElement(selector) {
return new Promise((resolve) => {
const checkInterval = setInterval(() => {
const element = typeof selector === 'function'
? selector()
: document.querySelector(selector);
if (element) {
clearInterval(checkInterval);
resolve(element);
}
}, 100);
});
}
(async function performActions() {
console.debug("[twitter-report] START");
try {
// Open the tweet menu by clicking the '...'
// let element = await waitForElement('[aria-label="More"');
// element.click();
// // Click "Report Post"
// element = await waitForElement('[data-testid="report"]');
// element.click();
/* "Hello" */
// Click "Start report"
let element = await waitForElement('[data-testid="OCF_CallToAction_Button"]');
element.click();
/* "Who is this report for?" */
// Click "Everyone on X"
element = await waitForElement('[aria-posinset="3"]');
element.click();
// Click "Next"
element = await waitForElement('[data-testid="ChoiceSelectionNextButton"]');
element.click();
/* "What is happening to everyone on X?" */
// Click "Spam"
element = await waitForElement('[aria-posinset="3"]');
element.click();
// Click "Next"
element = await waitForElement('[data-testid="ChoiceSelectionNextButton"]');
element.click();
/* "How is @scammer doing this?" */
// Click "Posting misleading or deceptive links, leading to scams, phishing, or other malicious links"
element = await waitForElement('[aria-posinset="1"]');
element.click();
// Click "Next"
element = await waitForElement('[data-testid="ChoiceSelectionNextButton"]');
element.click();
/* "It sounds like you want to make a report for platform manipulation and spam" */
// Click "Yes, continue"
element = await waitForElement('[data-testid="ocfSettingsListNextButton"]');
element.click();
/* "Let's make sure we have this right" */
// Click "Submit"
element = await waitForElement('[data-testid="ocfSettingsListNextButton"]');
element.click();
/* "Thanks for helping make X better for everyone" */
// Click "Block @scammer"
const blockButton = await waitForElement(() => {
let buttons = document.querySelectorAll('div[role="button"] > div > span');
for (const btn of buttons) {
if (btn.innerHTML.includes('Block ')) {
return btn;
}
}
return null;
});
blockButton.click();
console.debug("[twitter-report] DONE");
} catch (error) {
console.error(error);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment