Ode to Tampermonkey
Most of us spend a lot of time in a web browser. It could be half or even more than half of working time and a lot of free time too. Depending on what one is doing, it might be tempting to try to optimize some boring manual tasks, improve the UI of some web application or hack a bit here and there to simplify your work or common routines.
In many cases, there is already a browser extension covering (entirely or partially) specific tasks (for example, brilliant Redefined GitHub). But it's not always what you may be looking for. What if you would like to write your own extension or automation? And do it quickly?
Learning how to create browser extensions can be interesting, entertaining, and useful at the same time. On the other hand, it might not be the most optimal way to test ideas, create PoCs, or simple automation since the initial overhead may be much bigger than the automation itself (and the time saved). However, there is one extension that makes creating extensions really easy and quick. Have you ever heard of Greasemonkey or Tampermonkey?
Those are respectively Firefox and Chrome extensions (well, Tampermonkey started supporting Firefox at some point too) which allow creating, so-called user scripts, which could run on any given page, having very similar abilities to regular browser extensions.
Tampermonkey (since I'm more into blink-based browsers) is one of my all-time favorite tools for automation, testing stuff, and creating PoCs. It is a little bit like Codepen or CodeSandbox for browser extensions which is also production-ready!
Sounds fun, please tell me more!
You probably wonder what's possible with Tampermonkey? As mentioned above, it has very similar capabilities to regular browser extensions. And what's that exactly?
As a general programming rule, the sky is the limit. So the main limitation is your imagination and sometimes technical things too (and the time you can spend on development 😉). Some of the most interesting scripts and PoCs I have tried so far:
Just before we dive in - many projects (such as mentioned below) can or even should be done using official APIs, regular HTTP requests, or dedicated integrations (e.g. Zapier). Running such stuff in the browser is usually one of the least efficient ways (due to browser overhead) so it's not the best "production" approach in some cases.
I want to play a game!
Space encounters... OGame... I spent some time in this space universe. And so the idea to create semi-automatic players was born. I created a script that was able to open a new tab, log in, check resources level and start building new buildings based on a predefined queue. And then move to the next account and do the same. The high-level idea was to create multiple accounts and then maybe sell them or just create a bot army 🤔🙊🙈
Wanna bet?
Sport bets... a quick way to get rich and bankrupt 😅 I was never a big fan of any sports team or an enthusiastic game watcher (however, I played football a lot as a teen). So knowledge-backed sports betting was not for me. But many betting platforms provide also so-called live betting - it is a type of betting where you can bet during a sporting event, not before it.
My assumption was that the closer the event end is the less likely the result will change. And so finding such bets and betting was the Tampermonkey script job. For example, a football match with 10 minutes till the end and result 1:0 or 2:0. The chances the winning team will change are low, but the betting odds are also quite low so it's not a big win.
Long story short, as they say, the house always wins (well, almost always) 🤷
I robot, I like...
I spent some time creating an Instagram bot for liking other posts based on selected keywords. This is rather self-explanatory and well, it worked 🤷 You can do a lot of stuff and use a lot of metrics and data in such cases to make it more efficient. You know... growth hacking.
Let's make this board even better!
At CKSource we started using GitHub Boards (it's called Projects officially) as soon as those were introduced. They work fine but are pretty basic when it comes to configuring issues flows. So we had created a backend integration to improve it (changing pipelines automatically, support for issues from different organizations, etc) based on webhooks.
Still, some things which could be added on the frontend cannot be done with backend service so we had also added Tampermonkey script to enhance UI. For example, showing the total workload of all tasks in any given pipeline (based on size:*
labels), showing how many issues are assigned to a given person, and generating summary based on issues present on board - text summary useful during company standups and table summary showing basic stats - how many tasks in progress and done and how much man-days covered.
Do I need to type that again?!
Most modern browsers provide a feature called autofill. It works in a way that the browser will automatically fill any form based on predefined or earlier filled data. It can work quite nice but it's rather simple - either it understands the form and fills it or not.
I'm an amateur runner and in the times of COVID many organized runs were canceled but others went virtual. This means one needs to send runs results by filling the form and sending a screenshot of the run from the app or watch. It is usually quick and easy but when there is a lot to upload it may become cumbersome. For example, for "1 mile for charity" run when you can upload each 1,6 km run (it can be from 20 km run split into 1,6 km parts) it can be a lot.
So I have created a simple script - when the page with submission form is opened, the script fills all the necessary data - first name, last name, and email address and then when run screenshot is uploaded (with a name pattern like something-7.53
), the script also fills the time, based on the file name (here 7 minutes 53 seconds). It was much faster than typing manually or copy/paste. Yes... and much faster than running those miles 😓
MindControl: on!
This one is interesting. Many browser extensions add UI elements (like buttons) to the webpage they work with. Such UI elements, well, do stuff when used. But usually, those extensions miss the ability to automate or schedule such tasks.
So the script can be used to schedule such tasks by simply clicking a button or a link based on a simple timer. Sounds trivial but can be very useful.
Let's slack a bit :)
If in your company you are working with git (especially GitHub) and Slack you may have a special channel where Slack bot posts all updates (issue opened, issue closed, new PR, reviewed PR, etc).
You may also have a meeting where you need to describe what you have done during the last X days (e.g. a day or week).
Having a script that will gather all the tasks you have touched (so where you were mentioned as an author or reviewer) from the Slack channel and create a human-readable summary out of it could be useful, couldn't it?
Still curious?
If you would like to know more or discuss anything, feel free to drop me a message. Also, this is part 1 as I plan to create another article that will cover more technical stuff and will show some code examples. Stay tuned!
Any thoughts?