Skip to content

A librarian plays with javascript for the first time

A few times this summer my work with libguides left me turning to people for help with what felt like basic stuff, and each time the answer was “Oh, here are 2 lines of javascript that’ll solve your problem.” So I got jealous. I want to be able to know when two lines of javascript will solve all my problems, and what two lines those might be. Plus, I hate bothering busy people for tiny stuff.

Meanwhile, the other librarians and I were trying to figure out a clear and consistent way to link to catalog records from our Book assets in Libguides. Sure, there’s a URL field there, but over and over we’ve seen people think that if the title is a link, that means that the full text is behind the link. So they open the catalog, see what is clearly information about a book, and then proceed to use the catalog’s search bar to “search inside the book.” Then they’re confused when they just get results for more books. So they open their book again, and try it again. Endless frustrating loop. Also, we actually do have quite a few ebooks, so it’s extra confusing when some of those linked book titles go to ebooks and some go to catalog records. Not a great usability scenario.

So I thought “Well, we can just put a little HTML link in the book’s description box that makes it clear that this link, unlike the title link, leads to a catalog record. But 1) writing a bunch of HTML by hand can lead to errors, and worse, 2) not everyone is comfortable writing HTML by hand. But we did really want a second URL field with clarifying language, reserving linked titles for ebooks.

This, then, was the perfect project for me to learn Javascript. What could possibly go wrong? Here are my two methods of teaching myself from scratch:

  1. W3schools (especially fiddling with their “try it” setups to see if I can figure out how and why things work)
  2. Googling everything I want to do, one thing at a time, and hoping someone else on Stackoverflow has asked a similar question, and that whatever answers they got there will work if copied and pasted into my code.

I started thinking I could get away with making a bookmarklet, but since it turns out that browsers generally don’t allow you to access your clipboard except in very limited circumstances, and that many websites (including our catalog and libguides, the only two sites I cared about) don’t let me inject HTML to build a popup form to get around the lack of access to the clipboard, I finally had to admit that a bookmarklet would not work for me.

So then, according to the developers who helped and encouraged me along over on Mokum, it was time to start thinking about coding a browser extension. It took me a couple of days to admit this to myself because it sounded scary and complicated, but eventually I took this tutorial and its sample files by the horns and dived in. Along the way I got valuable hints from a friend to pay attention to the order of operations (at this point that means I just try things in various orders, but some day soon I hope to actually know what I’m doing), and to use the built in “Inspect” console in Chrome to debug the Javascript (which until now I’d only thought about as being a tool for HTML and CSS stuff).

And today, nine days later, I published my extension to Chrome and to Firefox! Now adding links to catalog records is quick and consistent for everyone in my department. (And if you want the unpacked files to mess around with, here you go, though I must warn you that I am NOT an expert so there may be stuff in here to make an expert weep, or laugh. Any and all suggestions for improvement are welcome.)

At this point I’m only just barely good enough to try lots of things in hopes that one of the things will work, and then to move on to the next thing. And I’m still very hampered by only having the vaguest idea what’s possible and (almost more important) what’s impossible. But who knows, maybe sometime soon I’ll have another tedious workflow that I can speed up by getting my computer to do a bunch of the tedious part for me. The world is my oyster!

Published inTools and Technology


  1. Carrie Hanson Carrie Hanson

    Congrats! I’m learning JavaScript in one of my classes this term and it’s tricky but definitely useful!

  2. Carrie, if you’re learning from an actual class you’ll quickly know more than me! So glad you’re doing it, though.

Comments are closed.