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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
1 // ==UserScript==
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
2 // @name twitter default following tab
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
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
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
7 // @match https://twitter.com/home
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
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
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
11 // @author nanaya
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
12 // @description Always select Following tab on first load
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
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
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
15 // ==/UserScript==
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
16
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
17 'use strict';
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
18
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
19 let selected = false;
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
20
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
21 const observer = new window.MutationObserver(selectFollowingTab);
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
22 let stopObservingTimeout;
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
23
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
24 function selectFollowingTab () {
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
25 if (selected) return;
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
26
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
27 const followingTab = document.querySelectorAll('[href="/home"][role=tab]')?.[1];
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
28 if (followingTab == null || followingTab.getAttribute('aria-selected') === 'true') return;
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
29
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
30 console.log("selecting 'Following' tab");
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
31 selected = true;
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
32 followingTab.click();
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
33 observer.disconnect();
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
34 clearTimeout(stopObservingTimeout);
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
35 }
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
36
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
37 function init () {
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
38 selectFollowingTab();
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
39 if (!selected) {
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
40 observer.observe(document, { childList: true, subtree: true });
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
41 }
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
42 stopObservingTimeout = setTimeout(() => {
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
43 console.log("couldn't find 'Following' tab, stop observing page");
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
44 observer.disconnect();
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
45 }, 60000);
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
46 }
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
47
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
48 if (document.readyState === 'loading') {
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
49 document.addEventListener('DOMContentLoaded', init);
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
50 } else {
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
51 init();
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
52 }