Mercurial > ec-userscripts
annotate twitter-default-following-tab.user.js @ 126:bf1f7164fd4f
Add more matches so fake redirects work
author | nanaya <me@nanaya.net> |
---|---|
date | Sat, 21 Jan 2023 02:30:07 +0900 |
parents | 31b1ab00cc7a |
children | a701294f38ff |
rev | line source |
---|---|
121 | 1 // ==UserScript== |
2 // @name twitter default following tab | |
3 // @namespace https://nanaya.net | |
126
bf1f7164fd4f
Add more matches so fake redirects work
nanaya <me@nanaya.net>
parents:
125
diff
changeset
|
4 // @match https://mobile.twitter.com/ |
bf1f7164fd4f
Add more matches so fake redirects work
nanaya <me@nanaya.net>
parents:
125
diff
changeset
|
5 // @match https://mobile.twitter.com/home |
bf1f7164fd4f
Add more matches so fake redirects work
nanaya <me@nanaya.net>
parents:
125
diff
changeset
|
6 // @match https://twitter.com/ |
121 | 7 // @match https://twitter.com/home |
8 // @grant none | |
123
87442313317d
Apparently tampermonkey requires run-at ?_?
nanaya <me@nanaya.net>
parents:
122
diff
changeset
|
9 // @run-at document-end |
126
bf1f7164fd4f
Add more matches so fake redirects work
nanaya <me@nanaya.net>
parents:
125
diff
changeset
|
10 // @version 1.0.3 |
121 | 11 // @author nanaya |
12 // @description Always select Following tab on first load | |
13 // @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
|
14 // @updateURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/twitter-default-following-tab.user.js |
121 | 15 // ==/UserScript== |
16 | |
17 'use strict'; | |
18 | |
19 let selected = false; | |
20 | |
21 const observer = new window.MutationObserver(selectFollowingTab); | |
22 let stopObservingTimeout; | |
23 | |
24 function selectFollowingTab () { | |
25 if (selected) return; | |
26 | |
27 const followingTab = document.querySelectorAll('[href="/home"][role=tab]')?.[1]; | |
28 if (followingTab == null || followingTab.getAttribute('aria-selected') === 'true') return; | |
29 | |
30 console.log("selecting 'Following' tab"); | |
31 selected = true; | |
32 followingTab.click(); | |
33 observer.disconnect(); | |
34 clearTimeout(stopObservingTimeout); | |
35 } | |
36 | |
37 function init () { | |
38 selectFollowingTab(); | |
39 if (!selected) { | |
40 observer.observe(document, { childList: true, subtree: true }); | |
41 } | |
42 stopObservingTimeout = setTimeout(() => { | |
43 console.log("couldn't find 'Following' tab, stop observing page"); | |
44 observer.disconnect(); | |
45 }, 60000); | |
46 } | |
47 | |
48 if (document.readyState === 'loading') { | |
49 document.addEventListener('DOMContentLoaded', init); | |
50 } else { | |
51 init(); | |
52 } |