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