Mercurial > ec-userscripts
view twitter-default-following-tab.user.js @ 138:76e8b47bbb03 default tip
[lashinbang-always-consent] check for login state
It's now required to turn off age check limit.
author | nanaya <me@nanaya.net> |
---|---|
date | Tue, 07 Jan 2025 16:07:50 +0900 |
parents | 7a7aafa65bae |
children |
line wrap: on
line source
// ==UserScript== // @name twitter default following tab // @namespace https://nanaya.net // @match https://mobile.x.com/* // @match https://x.com/* // @grant none // @run-at document-start // @version 1.1.2 // @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 // @updateURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/twitter-default-following-tab.user.js // ==/UserScript== 'use strict'; let selected = false; let observing = true; function isHome () { return window.location.pathname === '/home'; } let resumeObserverTimeout; // prevent reselect on browser back/forward navigation function pauseObserver () { console.debug('pausing observer'); observing = false; clearTimeout(resumeObserverTimeout); resumeObserverTimeout = setTimeout(() => { console.debug('resuming observer'); observing = true; selected = isHome(); }, 1000); } function selectFollowingTab () { if (!observing) return; if (!isHome()) { selected = false; return; } if (selected) return; const followingTab = document.querySelectorAll('a[href="/home"][role=tab]')?.[1]; if (followingTab == null) return; if (followingTab.getAttribute('aria-selected') === 'true') { selected = true; return; } console.log('selecting "Following" tab'); selected = true; followingTab.click(); } new window.MutationObserver(selectFollowingTab).observe(document, { childList: true, subtree: true }); selectFollowingTab(); window.addEventListener('popstate', pauseObserver);