Mercurial > ec-userscripts
view twitter-default-following-tab.user.js @ 123:87442313317d
Apparently tampermonkey requires run-at ?_?
author | nanaya <me@nanaya.net> |
---|---|
date | Sat, 21 Jan 2023 02:00:59 +0900 |
parents | 34eca18d4cbd |
children | 6d280338e113 |
line wrap: on
line source
// ==UserScript== // @name twitter default following tab // @namespace https://nanaya.net // @match https://twitter.com/home // @match https://mobile.twitter.com/home // @grant none // @run-at document-end // @version 1.0.1 // @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(); }