Last active
January 27, 2023 08:24
-
-
Save illixion/229c6229bfed8af2d4cf1eabbf518d0d to your computer and use it in GitHub Desktop.
This file contains 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 default Following tab | |
// @description Keep Following tab as your default tab | |
// @version 1.0 | |
// @author Ixion (illixion.com) | |
// @downloadURL https://gist.github.com/illixion/229c6229bfed8af2d4cf1eabbf518d0d/raw/fa20182836b68c77640ed09f47e31f88f970f080/Twitter%2520default%2520Following%2520Tab.js | |
// @match https://twitter.com/home | |
// @match https://mobile.twitter.com/home | |
// ==/UserScript== | |
function getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
(function () { | |
'use strict'; | |
var interval = setInterval(function () { | |
// get the tab that has tabindex="-1" and has a span child with text "Following" | |
var tab = getElementByXpath('//*[@role="tab" and @tabindex="-1" and .//span[text()="Following"]]'); | |
if (tab) { | |
tab.click(); | |
// if aria-selected is true, then break the loop | |
if (tab.getAttribute('aria-selected') === 'true') { | |
clearInterval(interval); | |
} | |
return; | |
} | |
}, 100); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment