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