XjSv/environment-marker

Make URL fragment support regex

RomainMichau opened this issue · 10 comments

Hello,
First of all, thanks for your work on this add-on, I love it.
I think that it would be nice to add regex support for the URL fragment.

Here's why:
I work in a company where we have two environments: prod and preprod

Our urls looks like that:
preprod: app.preprod.company.in
prod: app.company.in

I can use the URL fragment preprod.company.in to detect preprod environment. However I cannot do the same for prod without using regex.
With regex support I would be able to do something like:
(?<!preprod ).company.in

What do you think of my idea?
I would be glad to help you by making a PR

XjSv commented

Thanks, I'm glad you like it. I initially made it for myself then decided to release it to the public. That's why initially it was lacking alot of features including this one because for my purpose it was good enough.

But you bring up a great point. As I use it more and more I'm finding it necessary to use regex instead of JavaScript's indexOf.

If you want to start working on a PR for this feature, please be my guest. If not, I will have some time in the next couple of days to implement this.

XjSv commented

I have made this change in this commit: 446b03c

As I mentioned in the commit comments, using RegExp does require some expertise to work with. Maybe there should be an option to to switch the search mode from Normal (indexOf) to Advanced (RegExp).

XjSv commented

I went ahead and added the "Enable RegExp" Options in the Options page.
When enabled it will use RegExp instead of indexOf. And it can be toggled on/off.

Enable-RegExp-Option

I will make some code optimizations before creating release v2.4 in the next day or two.
If you want to test it you can run a build by executing npm run build and manually loading the package.

Good idea to add an "Enable RegExp" option.
However when using complex regex it breaks the popup:
Here it try to use the regexp (?<!preprod).company.in
image

But it works like a charm for more simple regex

XjSv commented

Thanks for the catch there. It was an issue with displaying the RegExp. Some characters like the less than < was being interpreted as HTML and breaking the page.

I added a HTML encoder using https://github.com/mathiasbynens/he.
The last commit should fix the display issue: ab02e5c

It now works fine with this commit

XjSv commented

Sounds good, I will be updating the docs and will be releasing v2.4 to include this feature.

XjSv commented

I will keep this issue open until the release is officially available.

XjSv commented

Version 2.4 is out https://github.com/XjSv/environment-marker/releases/tag/v2.4 and approved in Firefox.
The Chrome release will be approved soon.