Bookmarklet

Bookmarklet

I’ve been pretty busy lately and haven’t had much time to create or post anything. I’m hip deep in a branch of the Chimera-md code making a rudimentary user authentication layer. More on that down the road. I have also signed up for a new painting featuring a sexy, new model, so you can look forward to that.

The only thing I think I have I could share right now is a useful little toy I made a bit ago. It is a bookmarklet, a little Javascript routine bound to a bookmark in my browser that can pop open a Visual Studio Code editor for any of the Markdown files on my Chimera-md instance.

I use the server regularly. (Dogfooding is the key to developing useful and usable software.) As I do, and run into errors and oversights in dusty, forgotten notes, I keep wanting to jump in and edit them on the fly. It would be a huge development effort to expose that functionality through the web server, but I have a solution that works well for the time being.

The bookmarklet pops open the current document URL in Visual Studio Code. VS Code registers itself with the OS to handle URLs in the form of vscode://path/to/your/file.ext, so at the most basic level, the bookmarklet invokes one of those URLs. The only tricky part is you need to map the web server’s path to what the local machine knows it as, because that’s what VS Code is going to expect. In my case, that’s using the SMB drive mappings I use to access the NAS drives from my laptop.

Here’s the final code snippet. I’ve injected newlines to make it more readable, but the version in browser all renders on a single line

javascript: (() => {
  var loc = window.location.href;
  loc = loc.split('/home/')[1];
  if (!loc.endsWith('.md')) {
    loc += 'Index.md';
  }
  window.location = `vscode://file/Volumes/Home/Documents/${loc}`;
})()