Mercurial > ec-userscripts
view twitter-default-following-tab.user.js @ 121:f235b50ebdd2
Add twitter default following tab
author | nanaya <me@nanaya.net> |
---|---|
date | Sat, 21 Jan 2023 01:21:54 +0900 |
parents | |
children | 34eca18d4cbd |
line wrap: on
line source
// ==UserScript== // @name twitter default following tab // @namespace https://nanaya.net // @match https://twitter.com/home // @grant none // @version 1.0.0 // @author nanaya // @description Always select Following tab on first load // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/twitter-default-following-tab.user.js // ==/UserScript== 'use strict'; let selected = false; const observer = new window.MutationObserver(selectFollowingTab); let stopObservingTimeout; function selectFollowingTab () { if (selected) return; const followingTab = document.querySelectorAll('[href="/home"][role=tab]')?.[1]; if (followingTab == null || followingTab.getAttribute('aria-selected') === 'true') return; console.log("selecting 'Following' tab"); selected = true; followingTab.click(); observer.disconnect(); clearTimeout(stopObservingTimeout); } function init () { selectFollowingTab(); if (!selected) { observer.observe(document, { childList: true, subtree: true }); } stopObservingTimeout = setTimeout(() => { console.log("couldn't find 'Following' tab, stop observing page"); observer.disconnect(); }, 60000); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); }