Skip to content

Instantly share code, notes, and snippets.

@ivan
Last active June 30, 2023 19:12
Show Gist options
  • Save ivan/ce2e721defccb4f64df5da967dab0d41 to your computer and use it in GitHub Desktop.
Save ivan/ce2e721defccb4f64df5da967dab0d41 to your computer and use it in GitHub Desktop.
Sort-of archiving a bunch of Twitter accounts' profile tabs
// ==UserScript=
// @name Click to show tweets from blocked and muted users
// @version 1.0
// @match https://twitter.com/*
// @match https://mobile.twitter.com/*
// @grant none
// ==/UserScript==
(() => {
dispatchEvent(new CustomEvent("single-file-user-script-init"));
addEventListener("single-file-on-before-capture-request", async event => {
event.preventDefault();
// Remove the bottom bar with "Did someone say … cookies?"
Array.from(document.querySelectorAll('div[data-testid=BottomBar]')).forEach(el => el.parentNode.removeChild(el));
try {
// Click the buttons to expand blocked and muted tweets
document.querySelectorAll('div.css-18t94o4.css-1dbjc4n.r-1niwhzg.r-42olwf.r-sdzlij.r-1phboty.r-rs99b7.r-15ysp7h.r-4wgw6l.r-1ny4l3l.r-ymttw5.r-f727ji.r-j2kj52.r-o7ynqc.r-6416eg.r-lrvibr').forEach(el => el.click());
// Wait a bit for Twitter's animations to change box geometries before saving
await new Promise(r => setTimeout(r, 2000));
} finally {
dispatchEvent(new CustomEvent("single-file-on-before-capture-response"));
}
});
})();
sf() {
ionice -c 3 nice -n 19 ~/opt/single-file-cli/single-file \
--max-parallel-workers 1 \
--user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" \
--browser-script ~/expand-blocked-and-muted-tweets.js \
--browser-executable-path google-chrome-unstable \
--browser-wait-delay 2000 \
--filename-template '{page-title} - {url-href-flat}.html' \
--filename-max-length 240 \
--browser-cookies-file ~/.cache/your-twitter-cookies.txt \
--browser-width 1920 \
--browser-height 32767 \
"$@"
}
for i in `cat ~/username-list`; do
echo $i
sf "https://twitter.com/$i"
sf "https://twitter.com/$i/with_replies"
sf "https://twitter.com/$i/media"
sf "https://twitter.com/$i/likes"
sf "https://twitter.com/$i/following"
sf "https://twitter.com/$i/followers"
done
@ivan
Copy link
Author

ivan commented Jun 30, 2023

@ivan
Copy link
Author

ivan commented Jun 30, 2023

--browser-height 32767 seemed to work best (I didn't try 1 higher, but >= 40000 resulted in small output files.)

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