piroor / copy-selected-tabs-to-clipboard

Provides ability to copy title and URL of selected tabs to the clipboard for Firefox 63 and later.
Other
75 stars 15 forks source link

Feature request: simplify URL's #11

Closed joshgold22 closed 4 years ago

joshgold22 commented 4 years ago

Short description

Either or both of the following would be helpful, but especially the first:

  1. (simple) Add a new placeholder for %URL_SIMPLE% (or perhaps a better name) that copies the URL stripped of everything after the first ?.

(e.g., given https://www.nytimes.com/interactive/2020/05/19/burst/compost-box-indoors-coronavirus.html?action=click&module=Top%20Stories&pgtype=Homepage&contentCollection=AtHome&package_index=0 copies https://www.nytimes.com/interactive/2020/05/19/burst/compost-box-indoors-coronavirus.html )

  1. (more flexible and could be designed in various ways) Add a separate preference to allow regular expression replacement in URLs, or some other kinds of modifications (similar to the Neat URL or Lean URL firefox addons)

To comment on priority, I would find 1 most helpful (and certainly most worthwhile versus the effort!) I would also find 1. helpful even if 2. is provided: Sometimes I'd want to strip arguments no matter the domain; and having 1. allows the user to decide how it will be copied when they choose a format from the menu.

piroor commented 4 years ago

OK, now %REPLACE(...)% is supported. It takes one base text and one or more matcher/replaced-text pairs, like: %REPlACE("base text", "matcher regexp 1", "replaced 1", "matcher regexp 2", "replaced 2", ...)%

piroor commented 4 years ago

The matcher part is treated as a JavaScript regular expression, case-insensitive and not global match. So, you can define exception domains with a negative lookahead. For example: %REPLACE("%URL%", "^((?!\w+://([^/]*\.)?(google\.com|duckduckgo\.com)/.*).*)\?.*$", "$1")%

piroor commented 4 years ago

The automated test may help you to understand detailed specs of the %REPLACE(...)% feature: https://github.com/piroor/copy-selected-tabs-to-clipboard/blob/master/test/test-replacer.js