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.

  • zeus ⁧ ⁧ ∽↯∼
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    1
    ·
    edit-2
    10 months ago

    that’s also a great idea, i’ll see if i can find a way to cram that into µblock. thank you for the idea


    edit: for anyone who wants to do a similar thing, here is the syntax for a µblock filter:

    /(lemm.ee|mlmym.org)/##body a[href*="/lemm.ee/u/Crul"]::after:style(content:"awesome";color:tomato!important;border:1px solid currentColor;border-radius:var(--bs-border-radius, 0.375rem);padding-inline:0.5ch;margin-left:0.5ch;)

    the regex at the beginning is so it should work on both lemm.ee & mlmym; Crul is the username to be replaced; awesome is the tag content; tomato can be any colour but it’s a nice muted red; the *= is so it works with mlmym’s url prefix, and federation suffices (e.g. /u/Crul@lemm.ee); the radius var should be lemmy-ui native but it falls back to 0.375em if the var is not found

    (also i made it look a little prettier / more native)


    i’ll have a look at the mlmym github, see if there’s anything simple i can do; i’ve never used docker, but perhaps i can figure it out

    (also by the way your little ^_^ doesn’t work on the default ui, it makes a superscript underscore)

    • CrulOP
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      10 months ago

      I just realized that you can also add text tags with the ::after pseudo-element:

      a[href="/u/username"]::after {
        content: " [TAG]";
      }
      

      also by the way your little ^_^ doesn’t work

      Thanks, fixed!