Creating and publishing a Greasy Fork script
I've been using a couple of GreasyFork scripts with Tampermonkey Firefox extension for a while. Only recently has a missing feature on a web page bothered me enough to consider creating a user script myself.
// ==UserScript== // @name Copy TrueGaming achievement list // @namespace https://damirscorner.com // @version 1.0.0 // @description Copies the achievements/trophies from the True Achievements... // @author Damir Arh // @license MIT // @supportURL https://github.com/damirarh/GreasyForkScripts // @match https://www.trueachievements.com/game/*/achievements* // @grant none // ==/UserScript==
const filterDropdownTitleElement = document.querySelector( "#btnFlagFilter_Options .title" );
const copyAnchor = document.createElement("a"); copyAnchor.setAttribute("href", "#"); copyAnchor.setAttribute("title", iconLabel); copyAnchor.style.marginLeft = "0"; copyAnchor.appendChild(copyIcon); copyAnchor.addEventListener("click", copyToClipboard); filterDropdownTitleElement.appendChild(copyAnchor);
A basic development environment is provided by the Tampermonkey extension. You can open it via the Add a new script... menu command:
When you save the script for the first time, it appears in its Installed userscripts list. You can open it in the built-in editor from there to modify it at a later time:
Admittedly, this approach adds some overhead to testing the script. Instead of simply saving it, I have to copy and paste it to the Tampermonkey editor and save it there. I found a Stackoverflow answer with instructions for loading the script in Tampermonkey directly from the file system but I couldn't get it to work. Despite that, for me the benefits of using Visual Studio Code overweigh the inconvenience of having to copy the script to test it.
Publishing a script on GreasyFork is just a matter of filling out a simple form. If you host your script on GitHub (or another Git host), the process is even simpler as you can import it from there. To automate updates, you can even set up a web hook.
You can check the script I've written in my GitHub repository. Of course, the code is very specific to the problem I was solving. Still, the general approach will be useful in other scenarios as well.