Mercurial > ec-userscripts
annotate twitter-default-following-tab.user.js @ 136:1e64e81370a3
Add nginx-https
author | nanaya <me@nanaya.net> |
---|---|
date | Tue, 27 Feb 2024 01:17:43 +0900 |
parents | f2a53a2b9a5b |
children | 7a7aafa65bae |
rev | line source |
---|---|
121 | 1 // ==UserScript== |
2 // @name twitter default following tab | |
3 // @namespace https://nanaya.net | |
127 | 4 // @match https://mobile.twitter.com/* |
5 // @match https://twitter.com/* | |
121 | 6 // @grant none |
127 | 7 // @run-at document-start |
128 | 8 // @version 1.1.1 |
121 | 9 // @author nanaya |
10 // @description Always select Following tab on first load | |
11 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/twitter-default-following-tab.user.js | |
124
6d280338e113
Apparently both are required? or recommended
nanaya <me@nanaya.net>
parents:
123
diff
changeset
|
12 // @updateURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/twitter-default-following-tab.user.js |
121 | 13 // ==/UserScript== |
14 | |
15 'use strict'; | |
16 | |
17 let selected = false; | |
127 | 18 let observing = true; |
121 | 19 |
127 | 20 function isHome () { |
21 return window.location.pathname === '/home'; | |
22 } | |
23 | |
24 let resumeObserverTimeout; | |
25 // prevent reselect on browser back/forward navigation | |
26 function pauseObserver () { | |
27 console.debug('pausing observer'); | |
28 observing = false; | |
29 clearTimeout(resumeObserverTimeout); | |
30 resumeObserverTimeout = setTimeout(() => { | |
31 console.debug('resuming observer'); | |
32 observing = true; | |
33 selected = isHome(); | |
34 }, 1000); | |
35 } | |
121 | 36 |
37 function selectFollowingTab () { | |
127 | 38 if (!observing) return; |
39 | |
40 if (!isHome()) { | |
41 selected = false; | |
42 return; | |
43 } | |
44 | |
121 | 45 if (selected) return; |
46 | |
128 | 47 const followingTab = document.querySelectorAll('a[href="/home"][role=tab]')?.[1]; |
127 | 48 if (followingTab == null) return; |
121 | 49 |
127 | 50 if (followingTab.getAttribute('aria-selected') === 'true') { |
51 selected = true; | |
52 return; | |
53 } | |
54 | |
55 console.log('selecting "Following" tab'); | |
121 | 56 selected = true; |
57 followingTab.click(); | |
58 } | |
59 | |
127 | 60 new window.MutationObserver(selectFollowingTab).observe(document, { childList: true, subtree: true }); |
61 selectFollowingTab(); | |
62 window.addEventListener('popstate', pauseObserver); |