comparison 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
comparison
equal deleted inserted replaced
120:f3f646436567 121:f235b50ebdd2
1 // ==UserScript==
2 // @name twitter default following tab
3 // @namespace https://nanaya.net
4 // @match https://twitter.com/home
5 // @grant none
6 // @version 1.0.0
7 // @author nanaya
8 // @description Always select Following tab on first load
9 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/twitter-default-following-tab.user.js
10 // ==/UserScript==
11
12 'use strict';
13
14 let selected = false;
15
16 const observer = new window.MutationObserver(selectFollowingTab);
17 let stopObservingTimeout;
18
19 function selectFollowingTab () {
20 if (selected) return;
21
22 const followingTab = document.querySelectorAll('[href="/home"][role=tab]')?.[1];
23 if (followingTab == null || followingTab.getAttribute('aria-selected') === 'true') return;
24
25 console.log("selecting 'Following' tab");
26 selected = true;
27 followingTab.click();
28 observer.disconnect();
29 clearTimeout(stopObservingTimeout);
30 }
31
32 function init () {
33 selectFollowingTab();
34 if (!selected) {
35 observer.observe(document, { childList: true, subtree: true });
36 }
37 stopObservingTimeout = setTimeout(() => {
38 console.log("couldn't find 'Following' tab, stop observing page");
39 observer.disconnect();
40 }, 60000);
41 }
42
43 if (document.readyState === 'loading') {
44 document.addEventListener('DOMContentLoaded', init);
45 } else {
46 init();
47 }