I've thought about using userscripts as a tool, or even a foundation, for teaching front-end web development as well but haven't had an opportunity to try it out yet (I'll update this when I do!), so please take my musings with a grain of salt.
The "power user" vs "user" mentality
Userscripts are fundamentally a productivity tool. They offer organization, standardization, convenience and automation for power users. These benefits aren't likely obvious to entry-level programmers, especially younger audiences who are generally happy interfacing with technology in a very direct, surface level manner and probably won't see a pressing need to add a usability feature to, say, avoid repetitive tasks in their favorite app.
While obvious educational opportunity exists here, I'd use caution to avoid over-emphasizing tools and concepts that are really geared towards programmers and power users rather than application users. It takes time for programming students to switch to a hacker/power user/automator mindset and appreciate things like git, design patterns, memory management, databases and so forth. I'd put userscripts in this bucket as well.
Teaching browser development tools is usually enough
When most of us teach broswer developer tools to entry-level programmers, we usually do fun stuff like the classic day-one activity of "hacking" Wikipedia or Google by changing article headers or search results. Although there's subtle practical power here that userscripts help harness, this is mostly a fun and zero-installation way to get them used to HTML, CSS and JS (what they are/do, what do they look like) and build familiarity with the tool they'll soon be using to debug their own sites.
It's powerful to show students that they can easily look at and even manipulate the source that powers the websites they're visiting. One of the amazing aspects of the web is that the source is right there in front of you! There's a big "wow" factor there.
But how far does the magic carry a curriclum? It's probably pretty short-lived, and a deep dive into the console has diminishing returns for early programmers. Students will want to get on to making their own app than messing endlessly with other people's apps, and for good reason. One must write HTML, CSS and JS from scratch to understand it, and no amount of developer tools offers this. For more experienced programmers, this is less of an issue.
Who's the audience?
As with any educational tool, audience is everything. If the audience is a bunch of adults that are tired of repetitive clicking at their jobs, userscripting seems like a great way to empower and engage them without much effort.
For younger audiences, I'd try for creative projects. Userscripts can automate playing online games like cookie clicker, manipulating a Discord chat in real-time, or tweeting responses to certain messages automatically. It'd be interesting to try to make online art with userscripts by applying radical and surprising alterations to web pages.
Even if these sort of projects are cool, it's not clear that anything more than copy-pasting code (written in, say, Notepad++ or an online editor) into the console is necessary.
Bookmarklets also offer persistence and relative ease of operation without a full-fledged userscript, with the downside that they're inelegant and more restrictive. I recommend The Coding Train's bookmarklet challenge. Interestingly, I don't see any userscript content (or suggestions that Daniel cover userscripts) from them.
A userscript-focused curriculum seems like a better fit for an audience of programmers who know HTML5 basics, have made a few basic sites, games and apps and want to apply their skills to something new and interesting.
Some advantages I can see of teaching JS (and HTML/CSS) through userscripts:
- Environment set up is easy and userscript manager extensions like Tampermonkey have a built-in editor
- The coding is approachable, with caveats below
- Students work with other people's code, develop an appreciation for the complexity of real websites and gain exposure to many useful concepts
- It's empowering to be able to customize popular websites
- There are plenty of opportunities for creative projects
- Because the site is already created, there's less of a feeling of blank canvas or intimidation of building a huge project from the ground up to make something cool and useful
- Students can explore existing scripts
- It's rather unorthodox, so your curriculum stands out from the crowd. It could catch on like Automate the Boring Stuff with Python, an incredible book that manages to teach programming through a productivity lens in a way that's accessible and fun for nearly all audiences with basic computer literacy.
- Could be dry and de-motivating for the wrong audience; userscripts tend to be productivity/tooling -centric
- Potentially too much reliance on the console environment at the expense of obviously-beneficial greenfield projects built by hand (inexperienced students will need to do those anyway -- userscripts aren't a drop-in substitute)
- Not really a key skill, writing userscripts is always a sideline even among web programmers
- Possibly diminished sense of ownership relative to a greenfield app project
- Websites can change a lot and have hidden or nondeterministic complexities like A/B testing that break userscripts (and your assignments) easily
- As suggested by OP, the massive size and complexity of sites can be intimidating, although dev tools does a great job of handling minified, modern production sites thanks to the live interactive virtual DOM tree
- Although the coding isn't typically advanced (running
document.querySelector() and calling
.click() or setting style attributes, injecting
innerHTML, etc), writing userscripts can easily slide into a plethora of advanced concepts like asynchrony, event listener behavior, DOM loading and resource requests, element visibility minutiae and countless other things an experienced programmer takes for granted or can research in situ, but are sometimes prohibitive to introduce to beginners.
Project idea brainstorm
"Fun" project ideas for "kids" (some adults qualify)
- "Prank" a site to change the behavior in a subtle way, like making buttons run away from the mouse when the user tries to click on them. I've done these with kids and they enjoy showing the sites to their parents, teachers and friends.
- Expanding on the Twitter/Discord userscript idea: you can add a
MutationObserver or poll the message feed. When certain messages appear, the script can type a response. As a simple idea, the response could be a quote or gif pulled from an API, or could perform simple commands like "add two numbers". This can create pretty exciting emergent behavior for students with multiple bots talking to each other. (Yes, you could write a legitimate Discord bot, but this achieves much of the same result with less effort)
- Create animations using
setInterval. Options are endless: make page text scroll like the old
<marquee>, make background colors morph to make psychedelic patterns (seizure warning), add an animation trail to the mouse cursor, stretch page images comedically...
- Think creatively: manipulate Wikipedia text to create a mad libs story, blackout poetry or interactive fiction narrative.
- HTML5 audio is wild. For starters, check out the Web Speech API. Students create a userscript which reads the contents of a website or lets them type into a website by voice.
- Pointless fun: add rainbow color schemes to serious government websites, replace depressing images in the news with unicorns, automatically trigger clicks on links to browse sites programmatically, for example to play seven steps to Jesus (probably use something other than Jesus, but the idea applies), etc.
- Use a machine learning library to analyze text sentiment on a page.
- Use a machine learning library to analyze a video stream and manipulate the page, for example, change background when you blink.
- More pointless fun: Make text shake when you type or add physics to webpages using Matter.js.
As with any technology project, there's a lot of potential for abuse here, so it's important to keep it fun and remind students about not spamming, being nice online and not accidentally deleting a profile or sending their bank account balance to a phisher because of a script run amok.
"Serious" project ideas for "adults" (some kids qualify)
- All things API: fetch data from somewhere and put it into something. For example, hovering over a word with the mouse fetches a dictionary definition that appears in a tooltip.
- Changing color schemes to improve usability on a site
- Macros for repetitive tasks and accessing features buried in menus
- Use localStorage or even a backend app with a database (could be hosted on glitch for free) to remember specific actions taken on a page, for example, keep track of songs listened to on Bandcamp
- Instead of wasting time watching the Gmail/Hotmail logo when booting up email, show news headlines, a random fact or random Wikipedia article
- Injecting Codemirror into textareas to use, say, Vim keybindings
- Improving page load times by blocking resource requests
- Automatically dismissing annoying pop ups
- Programmatically importing data into forms
- Scraping data that isn't easily copy-pasteable and without writing a back-end app
- Filtering unwanted posts and distracting features in social media streams
- Did I mention web audio?
It turns out these are basically console/bookmarklet projects that aren't exactly essential to userscripting per se (and in many cases not inherent to the console environment), although userscripting certainly can help facilitate delivery.
Also, much of these ideas are already implemented as bookmarklets, pre-written userscripts or browser extensions (extensions are another thing worth considering for this sort of curriculum). It's OK to reinvent the wheel in the interests of learning and having fun.
To summarize, userscripts are an interesting tool and there's definitely plenty of potential for educational use. A strong curriculum targeted to the right audience could offer an original angle to learning programming, but at the end of the day, the focus would really be on manipulating sites through the console and developer tools, with userscripts a handy way to streamline that process rather than an end in and of themselves.