2020-10-08, updated: 2024-03-12
Tested with Nyxt 2 Pre-release 3.
Bookmarklets for better browsing
Bookmarklets are a feature in Nyxt that allow you to quickly create and consume snippets of JavaScript.
Wikipedia provides a succinct introduction and historical context:
A bookmarklet is a bookmark stored in a web browser that contains JavaScript commands that add new features to the browser. Bookmarklets are unobtrusive JavaScripts stored as the URL of a bookmark in a web browser or as a hyperlink on a web page. Bookmarklets are usually JavaScript programs.
Unlike in typical browsers, bookmarklets are not second-class citizens relegated to bookmarks- they are first-class commands! Because of their status in Nyxt, you can:
- bind snippets of JavaScript to a hotkey
- chain JavaScript snippets in your workflows/command invokations
- save snippets of JavaScript for later use
Defining bookmarklets in Nyxt is straightforward:
(define-bookmarklet-command color-internal-external-links
"Color internal links red, external links blue, and in-page links orange."
"(function(){var i,x; ...")
You provide:
- A name for your bookmarklet, this corresponds to its function/command
- A documentation string describing what the bookmarklet does
- Any JavaScript code you would like to run
… and that's it!
We've included a collection of Bookmarklets we think would be useful in our bookmarklets.lisp
file. They include commands to:
color-internal-external-links
: Color internal links red, external links blue, and in-page links orange.urls-as-link-text
: Changes the text of links to match their absolute URLs.hide-visited-urls
: Hide visited URLs.toggle-checkboxes
: Toggle all checkboxes.view-password-field-contents
: View passwords on page.show-hidden-form-elements
: Show hidden form elements.enlarge-textareas
: Increase height of all text areas by 5 vertical lines.show-textbox-character-count
: Displays a running count of the characters in each textbox.highlight-regexp
: Highlights each match for a regular expression.zoom-images-in
: Zoom images in.zoom-images-out
: Zoom images out.sort-table
: Sort a table alphabetically.number-table-rows
: Add numbers to table rows.number-lines
: Numberlines in plaintext documents and PRE tags.transpose-tables
: Transpose all table row and columns.remove-color
: Remove color from web pages.remove-images
: Remove images from web pages.hue-shift-positive
: Shift the colors of the web page with a positive hue.hue-shift-negative
: Shift the colors of the web page with a negative hue.increase-brightness
: Increase the brightness of the web page.decrease-brightness
: Decrease the brightness of the web page.invert-color
: Invert the color of the web page.
The currently provided bookmarklets were sourced from Jesse Ruderman's public domain works.
A great illustration of how useful bookmarklets can be is shown below. We start with the Wikipedia page for Salmon.
After executing our sort-table
bookmarklet, every single table has a header above it that we can use to sort the elements in the table alphabetically, by column.
We were then able to click and sort by "Scientific Name".
We hope you enjoy using these bookmarklets and find many more to add to your collection!
Thanks for reading :-)
Did you enjoy this article? Register for our newsletter to receive the latest hacker news from the world of Lisp and browsers!
- Maximum one email per month
- Unsubscribe at any time