Mercurial > ec-userscripts
annotate twitter-default-following-tab.user.js @ 125:31b1ab00cc7a
Not sure how tampermonkey even work
author | nanaya <me@nanaya.net> |
---|---|
date | Sat, 21 Jan 2023 02:15:02 +0900 |
parents | 6d280338e113 |
children | bf1f7164fd4f |
rev | line source |
---|---|
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 |
123
87442313317d
Apparently tampermonkey requires run-at ?_?
nanaya <me@nanaya.net>
parents:
122
diff
changeset
|
7 // @run-at document-end |
125 | 8 // @version 1.0.2 |
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; | |
18 | |
19 const observer = new window.MutationObserver(selectFollowingTab); | |
20 let stopObservingTimeout; | |
21 | |
22 function selectFollowingTab () { | |
23 if (selected) return; | |
24 | |
25 const followingTab = document.querySelectorAll('[href="/home"][role=tab]')?.[1]; | |
26 if (followingTab == null || followingTab.getAttribute('aria-selected') === 'true') return; | |
27 | |
28 console.log("selecting 'Following' tab"); | |
29 selected = true; | |
30 followingTab.click(); | |
31 observer.disconnect(); | |
32 clearTimeout(stopObservingTimeout); | |
33 } | |
34 | |
35 function init () { | |
36 selectFollowingTab(); | |
37 if (!selected) { | |
38 observer.observe(document, { childList: true, subtree: true }); | |
39 } | |
40 stopObservingTimeout = setTimeout(() => { | |
41 console.log("couldn't find 'Following' tab, stop observing page"); | |
42 observer.disconnect(); | |
43 }, 60000); | |
44 } | |
45 | |
46 if (document.readyState === 'loading') { | |
47 document.addEventListener('DOMContentLoaded', init); | |
48 } else { | |
49 init(); | |
50 } |