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
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
127
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
4 // @match https://mobile.twitter.com/*
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
5 // @match https://twitter.com/*
121
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
6 // @grant none
127
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
7 // @run-at document-start
128
f2a53a2b9a5b More precise selector
nanaya <me@nanaya.net>
parents: 127
diff changeset
8 // @version 1.1.1
121
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
9 // @author nanaya
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
10 // @description Always select Following tab on first load
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
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
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
13 // ==/UserScript==
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
14
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
15 'use strict';
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 let selected = false;
127
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
18 let observing = true;
121
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
19
127
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
20 function isHome () {
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
21 return window.location.pathname === '/home';
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
22 }
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
23
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
24 let resumeObserverTimeout;
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
25 // prevent reselect on browser back/forward navigation
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
26 function pauseObserver () {
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
27 console.debug('pausing observer');
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
28 observing = false;
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
29 clearTimeout(resumeObserverTimeout);
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
30 resumeObserverTimeout = setTimeout(() => {
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
31 console.debug('resuming observer');
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
32 observing = true;
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
33 selected = isHome();
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
34 }, 1000);
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
35 }
121
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 selectFollowingTab () {
127
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
38 if (!observing) return;
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
39
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
40 if (!isHome()) {
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
41 selected = false;
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
42 return;
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
43 }
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
44
121
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
45 if (selected) return;
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
46
128
f2a53a2b9a5b More precise selector
nanaya <me@nanaya.net>
parents: 127
diff changeset
47 const followingTab = document.querySelectorAll('a[href="/home"][role=tab]')?.[1];
127
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
48 if (followingTab == null) return;
121
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
49
127
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
50 if (followingTab.getAttribute('aria-selected') === 'true') {
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
51 selected = true;
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
52 return;
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
53 }
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
54
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
55 console.log('selecting "Following" tab');
121
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
56 selected = true;
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
57 followingTab.click();
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
58 }
f235b50ebdd2 Add twitter default following tab
nanaya <me@nanaya.net>
parents:
diff changeset
59
127
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
60 new window.MutationObserver(selectFollowingTab).observe(document, { childList: true, subtree: true });
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
61 selectFollowingTab();
a701294f38ff More reliable state handling
nanaya <me@nanaya.net>
parents: 126
diff changeset
62 window.addEventListener('popstate', pauseObserver);