Skip to content

Instantly share code, notes, and snippets.

@kosugi
Last active June 4, 2023 06:45
Show Gist options
  • Save kosugi/57d3e31f5e5c07d1057cd5ce130a1502 to your computer and use it in GitHub Desktop.
Save kosugi/57d3e31f5e5c07d1057cd5ce130a1502 to your computer and use it in GitHub Desktop.
No more tweets
// ==UserScript==
// @name No More Tweets
// @namespace https://twitter.com/kosugi
// @version 0.1
// @description NO MORE TWEETS
// @match https://twitter.com/*
// @grant none
// ==/UserScript==
const moreTweetsContents = ({en: ['More Tweets', 'Discover more'], ja: ['その他のツイート', 'もっと見つける']})[document.querySelector('html').lang];
let flags = 0;
function doIt() {
const candidates = Array.from(document.querySelectorAll('div[data-testid="cellInnerDiv"]'));
const target = (() => {
for (const e of candidates) {
const span = e.querySelector('h2[aria-level="2"][role="heading"] span');
if (span && moreTweetsContents.includes(span.textContent)) {
return e;
}
}
})();
if (!target || window.innerHeight < target.getBoundingClientRect().top) {
flags = 0;
return 1000;
}
const numProceeds = candidates.reduce(([num, isAfter], e) => {
if (e === target) {
isAfter = true;
e.style.visibility = 'hidden';
}
else if (isAfter && e.style.display !== 'none') {
++num;
e.style.display = 'none';
}
return [num, isAfter];
}, [0, false]);
flags = 0xF & (flags * 2 + (numProceeds === 0));
return (flags === 0xF) ? 1000 : 100;
}
(function onInterval() { setTimeout(onInterval, doIt()); })();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment