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 ⁧ ⁧ ∽↯∼@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    oh crul it’s you!

    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)

    • Crul@lemm.eeOP
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      1 year ago

      the communities’ ids are in the url, so the reddit method doesn’t work unless i memorise the id №.

      Yeah… that’s why I didn’t tried that yet. I’m waiting a bit to see what frontend options are.

      The good news is that mlmym uses the community name for posting and searches:

      To make it work with community ids, I planned to have something like the “subreddit shorcuts” from the “post to reddit” bookmarklet (see below). Not ideal, but better than nothing.

      i don’t suppose you could share some of those?

      Sure, here there are. I realized that a couple of them are not really bookmarklets, but simple bookmarks with the %s param. You need to add a keyword and use it with keyword string to be searched.

      lemmy all search

      https://lemm.ee/search?q=%s&type=All&listingType=All&page=1&sort=TopAll

      lemmy community search

      https://lemm.ee/search?q=%s&type=Communities&listingType=All&page=1&sort=TopAll

      get link in markdown

      Execute it without param (e.g.: link) to get [title](url)
      Execute it with a param (link text to display) to get [text to display](url)
      It will show the result in a prompt and you can copy from there. The prompt itself has no effect, it doesn’t matter how you close it.

      pretty printed code
      (function() {
          var title = ("%s" || document.title)
              .replace("[", "\\[")
              .replace("]", "\\]");
      
          prompt("Title:", `[${title}](${document.location.href})`);
      })()
      

      One liner:

      javascript:(function() {var title = ("%s" || document.title).replace("[", "\\[").replace("]", "\\]");prompt("Title:", `[${title}](${document.location.href})`);})()
      

      I also have one to get just the title of a page, but I leave that as an exercise to the reader :D. It’s very easy to modify the link one.

      post to reddit

      Use it with the subreddit name (e.g.: post CassetteFuturism) or the subreddit shortcut (e.g.: post cf).
      If executed with no param, it will show a list of “shortcuts” and will ask you to select one.

      The shortcuts are in the `subKeys``dictionary. That’s the trick that could be used to assign the community ids from the community names (or custom shortcuts). Not practical for a random commmunity, but manageable for the most common ones.

      pretty printed code
      function() {
          var subKeys = {
              cf: 'CassetteFuturism',
              it: 'ImaginaryTechnology',
              iv: 'ImaginaryVehicles',
              ap: 'ApocalypsePorn',
              ss: 'Simon_Stalenhag',
              sw: 'spainwave',
              sk: 'sketches',
          };
          var subreddit = '%s';
          if (!subreddit) {
              var promptText = "Type subreddit:";
              for (var shortcut in subKeys) promptText += `\n- ${shortcut}: ${subKeys[shortcut]}`;
              subreddit = prompt(promptText);
          }
          if (!subreddit) return;
          if (subKeys[subreddit]) subreddit = subKeys[subreddit];
          var title = document.title;
          var url = encodeURIComponent(document.location.href);
          window.open(`https://www.reddit.com/r/${subreddit}/submit?url=${url}&title=${title}`);
      })()
      

      One liner:

      javascript:(function() {var subKeys = {cf: 'CassetteFuturism',it: 'ImaginaryTechnology',iv: 'ImaginaryVehicles',ap: 'ApocalypsePorn',ss: 'Simon_Stalenhag',sw: 'spainwave',sk: 'sketches',};var subreddit = '%s';if (!subreddit) {var promptText = "Type subreddit:";for (var shortcut in subKeys) promptText += `\n- ${shortcut}: ${subKeys[shortcut]}`;subreddit = prompt(promptText);}if (!subreddit) return;if (subKeys[subreddit]) subreddit = subKeys[subreddit];var title = document.title;var url = encodeURIComponent(document.location.href);window.open(`https://www.reddit.com/r/${subreddit}/submit?url=${url}&title=${title}`);})()
      

      (…continues on next comment?)