If you assign the keyword redditsearch to that bookmarklet, you can type redditsearch PixelArt zelda on the firefox navbar and you will be reditected to the Reddit search for 'zelda' on r/PixelArt.
In general this makes the navbar a very powerful command line in which you can add any command with multiple params.
It seems Mozilla has plans to get rid of this feature, see the ticket Migrate keyword bookmarks into about:preferences managed Search Engines. The good news is that the last comment, besides mine asking them not to remove this functionality, is from some years ago. I hope they change their mind, or forget about it...
TIP: If you don't want to remember the param order, you can also ask for them with a prompt if no arguments are specified:
javascript:(function(){
var args = '%s'.split(' ');
var subreddit = args[0] != "" ? args[0] : prompt("Enter the subbreddit:");
if (!subreddit) return;
var search = args.length > 1 ? args[1] : prompt("Enter the text to search:");
if (!search) return;
document.location.href = "https://www.reddit.com/r/" + subreddit + "/search/?q=" + search + "&include_over_18=on&restrict_sr=on&t=all&sort=new";
})();
Bookmarklet format:
javascript:(function(){ var args = '%s'.split(' '); var subreddit = args[0] != "" ? args[0] : prompt("Enter the subbreddit:"); if (!subreddit) return; var search = args.length > 1 ? args[1] : prompt("Enter the text to search:"); if (!search) return; document.location.href = "https://www.reddit.com/r/" + subreddit + "/search/?q=" + search + "&include_over_18=on&restrict_sr=on&t=all&sort=new"; })();
Sorry for the reddit examples, this was posted originally on r/firefox some time ago and adapting them to lemmy seemed a bit too much work :P.
I must admit that I've only used the multiple-param part in very few cases, but the main "bookmarklet keyword with param" is very useful, some examples I have:
Custom searches: lemmy communities, lemmy content
Get the link to a page with markdown format: [title or custom text](https://url...)
Post image or URL to a subreddit (I need to migrate this one for lemmy)
i don't suppose you could share some of those? i just had a quick look, but the lemmy search syntax is different to reddit - the communities' ids are in the url, so the reddit method doesn't work unless i memorise the id №... (i wish the lemmy devs weren't so obsessed with numbers)
Not that I'm aware of. I think they are so simple that there isn't very much to say about them. They are just plain javascript that works as if you typed it on the console. Although, there a couple of tricky things.
EDIT: I'm not saying javascript is simple. Bookmarklets can be very complex, but that's just javascript. If you know how to do it on the browser console, you just need to write it in a one-liner and it will work as a bookmark (with the caveats that I talk about later).
If you follow that post, there will be no problem. But you will have issues if you don't use the "auto-executed anonymous function" wrapper.
And, as the post says, you need to write all semicolons and brackets { } to avoid funny things when removing line breaks.
EDIT-2: I forgot to mention the %s part, I think that's not its intended use. I know it from keyworded regular-non-js bookmarks used for searches. See Using keyword searches - MozillaZine Knowledge Base. The great part is that it also works with bookmarklets :).
The other tricky part is the inconvenience of editing them after some time if you don't have a pretty-formatted version. I've been able to hack a script to read bookmarklets from Firefox places DB, pretty-format, open in VIM and re-convert them to one-liners after the edition. I wasn't able to save them automatically to Firefox because some secure-hash stauff, so I still need to copy-paste them manuall at the end.
Thanks a million, great info once again! I didn't realize that the %s was simply replaced (because that seems a little dirty), but it makes sense in the bookmark context.
Yeah, the development flow is a little tricky :) Ideally it would be nice to re-apply/import them automatically without user interaction and/or run automated testing. I fiddled a little with the command-line (for testing), ie. firefox -url "javascript:...", but it doesn't seem to work. Accessing the places database directly would be great of course. I've been thinking about using the enterprise policies, but haven't gotten around to testing it.