I know firefox has the very useful “Copy clean Link” option in the context menu, but I would like a similar feature for copying links from any other software, like spotify for example. So I am looking for some software that hooks into the clipboard pipeline, and cleans any URL that gets added. I tried googling for something like it, but was completely unsuccessful. Does anyone have a clue how I might go about achieving this?

Thanks in advance :)

Edit: I found out about klipper’s actions, which provide the option to run a command when a string that matches a regex is added to the clipboard buffer. I am not sure how to properly use this though, so any help is appreciated!

    • Flagstaff@programming.dev
      link
      fedilink
      English
      arrow-up
      1
      ·
      27 days ago

      It rarely ever does anything in my experience.

      Anyway, I built a URL-cleaning script in AutoHotkey, but that’s Windows-only; I, too, am on the hunt for a Linux equivalent. Maybe this could be done in SikuliX or Espanso, via a Python script, but I suck at Python so far.

      • cmnybo@discuss.tchncs.de
        link
        fedilink
        English
        arrow-up
        0
        ·
        27 days ago

        It’s never worked for me either. The ClearURLs addon has a function to copy a clean URL and that works great though. It’s open source, so maybe someone could turn its cleaning function into a program that could be used for the clipboard.

  • JubilantJaguar@lemmy.world
    link
    fedilink
    arrow-up
    0
    arrow-down
    1
    ·
    27 days ago

    You never define “clean”.

    To strip excess URL parameters (i.e. beginning “&”, almost certainly junk) if the clipboard buffer contains a URL and only a URL (Wayland only):

    if url=$(printf '%s' "$(wl-paste --no-newline | awk '$1=$1' ORS=' ')" | egrep -o 'https?://[^ ]+') ; then
      wl-copy "${url%%\&*}"
    fi
    
    • traches@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      0
      ·
      27 days ago

      Query parameters are junk? They have tons of legitimate uses, they’re one of the better places to keep state.

      • silly goose meekah@lemmy.worldOP
        link
        fedilink
        arrow-up
        0
        ·
        26 days ago

        As a WebDev… URL parameters are definitely not the place to keep state… Were not in the 00’s anymore. They do have legit uses, but we have JS localStorage nowadays.

        • traches@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          1
          ·
          26 days ago

          They have pretty different use cases. Localstorage is for when you want persistence across page loads, not necessarily specific to any particular page but specific to a browser. An example would be storing user-selected light or dark mode.

          Query parameters are specific to a page/URL and you get a lot of things for free when you use them:

          • back/forward navigation
          • bookmarking
          • copy-paste to share
          • page level caching
          • access on both server and client

          Query parameters are good for things like searches, filters, sorting, etc