How to create JavaScript bookmarks.

Table of Contents

1 Why?

Because they're useful and fun. You can make a button that runs whatever JS you want, one useful example is a script that modifies all links that lead to a new browser tab (they can be irritating) so they no longer do. You can take it further and make a script that removes a paywall from site you use.

2 What you need?

Some JavaScript skills.

A working browser, works both on Chrome-based (M$ Edge, Chromium, Brave, etc) and Firefox-based (Librewolf, Mullvad etc) provided they're reasonably modern.

Code/text editor of choice (optional) (browsers have a built-in editor that can do the job just fine)

3 How?

It's pretty simple. First you need to write a script that does whatever you want it to do that works when copy-pasted into your browser's console (in DevTools), then you throw it into any JS-minifier to make it smaller and what's more important to remove all newlines. Now you've got long string of JS code that (hopefully) still works, and the fun part begins here you need a `javascript:` URL. If you've played with it before you'll know that it's not meant for multi-line code which is why you need to make it a single statement, the template for it looks like that:

javascript:(() => {your code})()

I'll break it down for you:

First part is javascript: "protocol", it tells your browser that this is code not something else i.e. link to pr0n site or sth.

() => {} is JS's lambda function declaration, it's a shorthand for declaring functions and it returns that function (or some object thingy, i'm not an JS expert) and it's enclosed in braces because of last part

Braces at the end call the function (or object-thingy) which runs your code.

This file was written without using LLMs and is therefore quite eco-friendly because my thinkpad uses little electricity and no water.

Author: montar

Created: 2025-08-13 Wed 22:10

Validate