Last active
January 20, 2023 19:37
-
-
Save tsukumijima/23e6980665913b82473eaedd00dbb0da to your computer and use it in GitHub Desktop.
Twitter ホームのデフォルトのタイムラインを「フォロー中」に切り替える UserScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name TwitterFollowingTimelineSwitcher | |
// @description Twitter ホームのデフォルトのタイムラインを「フォロー中」に切り替える UserScript | |
// @match https://twitter.com/* | |
// @namespace https://gist.github.com/tsukumijima | |
// @updateURL https://gist.github.com/tsukumijima/23e6980665913b82473eaedd00dbb0da/raw/TwitterFollowingTimelineSwitcher.user.js | |
// @downloadURL https://gist.github.com/tsukumijima/23e6980665913b82473eaedd00dbb0da/raw/TwitterFollowingTimelineSwitcher.user.js | |
// @supportURL https://gist.github.com/tsukumijima/23e6980665913b82473eaedd00dbb0da | |
// @author tsukumi | |
// @version 1.0.2 | |
// @license MIT | |
// ==/UserScript== | |
(async () => { | |
'use strict'; | |
const switchToFolowing = async () => { | |
while (true) { | |
await new Promise(resolve => setTimeout(resolve, 0.5 * 1000)); | |
try { | |
if (location.pathname !== '/' && location.pathname !== '/home') { | |
break; | |
} | |
if (document.querySelectorAll('a[href="/home"][role="tab"]')[1].getAttribute('aria-selected') === 'true') { | |
console.log('Twitter Home Switch to "Following": Suceeded'); | |
break; | |
} | |
document.querySelectorAll('a[href="/home"][role="tab"]')[1].click(); | |
} catch { | |
} | |
} | |
}; | |
switchToFolowing(); | |
// ref: https://stackoverflow.com/a/64927639/17124142 | |
window.history.pushState = new Proxy(window.history.pushState, { | |
apply: (target, thisArg, argArray) => { | |
const url = argArray[2]; | |
if (url === '/' || url === '/home') { | |
switchToFolowing(); | |
} | |
return target.apply(thisArg, argArray); | |
}, | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment