Last active
October 25, 2023 15:38
-
-
Save abcang/b7dea73a9a6f64990f695e9909ca9027 to your computer and use it in GitHub Desktop.
Twitter PWA Single Column
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 Twitter PWA Single Column | |
// @namespace https://gist.github.com/abcang/b7dea73a9a6f64990f695e9909ca9027/raw/twitter-pwa-single-column.user.js | |
// @version 0.3 | |
// @description TwitterのPWAを1カラムで使いやすくする | |
// @author abcang | |
// @match https://twitter.com/* | |
// @grant none | |
// @downloadURL https://gist.github.com/abcang/b7dea73a9a6f64990f695e9909ca9027/raw/twitter-pwa-single-column.user.js | |
// @updateURL https://gist.github.com/abcang/b7dea73a9a6f64990f695e9909ca9027/raw/twitter-pwa-single-column.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// PWA以外では動かさない | |
if (!window.matchMedia('(display-mode: standalone)').matches) { | |
return | |
} | |
// TL上部に表示されるツイート入力欄を非表示にする | |
// 最低1pxないと新しい投稿を読み込めない | |
const tlTextArea = '[data-testid="primaryColumn"] > [tabindex="0"] > div:has([data-testid="tweetTextarea_0"])'; | |
const css =` | |
${tlTextArea} { | |
height: 1px; | |
opacity: 0; | |
pointer-events: none; | |
} | |
`; | |
const style = document.createElement('style'); | |
style.appendChild(document.createTextNode(css)); | |
document.head.appendChild(style); | |
// TLの画面でスクロールが一番上にあれば自動的に新しいツイートを読み込む | |
setInterval(() => { | |
if (window.scrollY > 0) { | |
return; | |
} | |
// TLの画面ではない場合はやめる | |
if (document.querySelectorAll(('[data-testid="primaryColumn"] [href="/home"]')).length === 0) { | |
return; | |
} | |
document.querySelector('[aria-label="X"]').click() | |
}, 20 * 1000) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment