Skip to content

Instantly share code, notes, and snippets.

@mpyw
Last active March 5, 2021 08:06
Show Gist options
  • Save mpyw/83d9f5232da96ed0095bb603d56e0f64 to your computer and use it in GitHub Desktop.
Save mpyw/83d9f5232da96ed0095bb603d56e0f64 to your computer and use it in GitHub Desktop.
新 Twitter で「最新のツイート」に強制的に切り替えるやつ
// ==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);
}
}
})();
})();
@mpyw
Copy link
Author

mpyw commented Jun 21, 2019

image

常にこれにキープされる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment