In Firefox you can combine JS bookmarklets, keywords and params to do something like this:
javascript:(function(){
var args = '%s'.split(' ');
alert(args);
})();
Useful example:
javascript:(function(){
var args = '%s'.split(' ');
var subreddit = args[0];
var search = args[1];
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];var search = args[1];document.location.href = "https://www.reddit.com/r/" + subreddit + "/search/?q=" + search + "&include_over_18=on&restrict_sr=on&t=all&sort=new";})();
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.
(... continues from previous comment, I was getting an error when I tried to post all in the same comment)
post image to reddit
I don't recommend this one, I haven't used in a while and it doesn't work great with most sites.
It should works very similar to the previous one, but looking for images on the page. It also writes my usual "Source: [title](url) blablabla" comment for the most common sites.
The result is a huge mess and very fragile. I post it more as an example of how you could do some things.
pretty printed code
(one-liner missing because I'm still getting an error)
EDIT: Yeah, lemmy doesn't like a single line with >5000 characters, hehe. Anyway, I don't recommend using this last one.
holy hell that is an absolute monolith of a bookmarklet though