Tampermonkey is pretty cool

2 minutes, 2021-03-06. Back to main page

The other day, I found myself wanting to scrape a bunch of logs from Discord. I’d written a Markov generator for fun, and I wanted to train it on a friend’s post history. Trouble is, Discord doesn’t exactly have a “scrape logs” button in its UI. I imagine a bot could do it easily enough, but I didn’t control a bot on that server.

Now, I’d previously heard Tampermonkey mentioned in passing. Tamper­monkey is a browser plugin that lets you run custom userscripts — snippets of javascript that execute automatically on certain domains. I injected a button into Discord that would automatically flip through pages of Discord search results, scrape the text from the results, and post it to a local Flask server with the fetch() API. Setting aside a couple hitches here and there, it worked quite nicely.

Today, I used it again. I find that it’s easy to waste time on Twitter, because you don’t know how long you’ve been using it for. Twenty minutes can go by without you actually realizing it. So I set up a userscript to run on https://twitter.com/*. It pings a local Go server every 30 seconds, and the server sends desktop notifications every five minutes letting you know how long you’ve been scrolling through Twitter. It stops timing you when the keep-alives stop rolling in. It works great.

I’m excited about future possibilities here. I’m usually pretty hesitant to install random browser plugins, because “browser plugin got taken over by bad actors” is a really easy vector for malware. But with Tampermonkey, I control the code I run. Browsers are one of the most important tools we use, and I’m excited to see the possibilities that open up to me with this kind of simple automation.

— Pan-fried, 2021-03-06. Back to top