Last active
March 5, 2021 08:06
-
-
Save mpyw/83d9f5232da96ed0095bb603d56e0f64 to your computer and use it in GitHub Desktop.
新 Twitter で「最新のツイート」に強制的に切り替えるやつ
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 で「最新のツイート」に強制的に切り替えるやつ | |
// @namespace https://twitter.com/mpyw | |
// @version 0.1 | |
// @description お節介機能を殺す | |
// @author mpyw | |
// @match https://twitter.com/home | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function getTwitterStore() { | |
const findInternal = (node) => { | |
return node._reactInternalFiber | |
|| node[Object.keys(node).find((key) => key.startsWith('__reactInternalInstance'))]; | |
} | |
let current = findInternal(document.querySelector('a[href="/compose/tweet"]')); | |
while (true) { | |
if (!current.return.stateNode) { | |
current = current.return; | |
} | |
if (current.return.stateNode.context && current.return.stateNode.context.store) { | |
break; | |
} | |
current = findInternal(current.return.stateNode); | |
} | |
return current.return.stateNode.context.store; | |
} | |
function forceLatestTweet() { | |
const store = getTwitterStore(); | |
store.dispatch({ | |
type: 'rweb/homeTimeline/SET_SETTING', | |
payload: { | |
useLatest: true, | |
}, | |
}); | |
} | |
function sleep(ms) { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} | |
(async () => { | |
while (true) { | |
try { | |
await sleep(1000); | |
while (true) { | |
forceLatestTweet(); | |
await sleep(60000); | |
} | |
} catch (e) { | |
console.error(e); | |
} | |
} | |
})(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
常にこれにキープされる