Skip to content

Instantly share code, notes, and snippets.

@eberfreitas
Created March 5, 2021 18:26
Show Gist options
  • Save eberfreitas/6b9ff71d242709c4fcf02bd5c14265fa to your computer and use it in GitHub Desktop.
Save eberfreitas/6b9ff71d242709c4fcf02bd5c14265fa to your computer and use it in GitHub Desktop.
Fuck Off Twitter!
// ==UserScript==
// @name Fuck off Twitter! - twitter.com
// @namespace Violentmonkey Scripts
// @match https://twitter.com/home
// @grant none
// @version 1.0
// @author Eduardo Cuducos - https://github.com/cuducos/fuckoff-twitter/blob/ec14293dda1467be71abb2549d2a36972e9e148f/twitter.js
// @description Changes from regular Twitter's homepage to latest tweets
// ==/UserScript==
const getBySelectorAndText = (selector, text) => {
const matches = document.querySelectorAll(selector);
for (let i = 0; i < matches.length; i++) {
if (matches[i].innerText == text) return matches[i];
}
};
const main = () => {
// Is it set to Home?
const home = getBySelectorAndText("h2>span[role=heading]", "Home");
if (home !== undefined) return;
// Let's open the menu to change it
document.querySelector("div[aria-label='Top Tweets on']").click();
// Let's get the link to change it to Latest tweets
const bt = getBySelectorAndText("div>div>span", "See latest Tweets instead");
if (bt === undefined) {
console.error("Cannot find link to change to Latest tweets");
return;
}
bt.click();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment