Jump to content
Tuts 4 You

How to change URL parts on fly?


LCF-AT

Recommended Posts

Hi guys,

I'am looking for an extension what can check the executed URL / Link for matching pattern and does change it on fly. Somehow I can not use uBlock Origin for this with any custom URL / pattern and need to find any extension or Tampamonkey script.

Example:

https://someurl.com/path1/path2/path3/...

now before the URL gets executed by mouse click etc 
I want to let check it and change it when pattern does match

My pattern could be like this....static

https://someurl.com/path1/
if match then change to
https://someurl.com/ring/

What means the result change should be...
https://someurl.com/ring/path2/path3/...

Pretty simple thing but as always I can not find a extension or script. I found some redirctor extensions but they are not doing that I need. In this example above I just need to change some parts in the middle only and keeping everything else.

I found a script here...

https://greasyfork.org/en/scripts/403100-url-replacer-redirector

....but I can not find the settings json anywhere in the TM page. Just can add the user includes sites but where to write the settings like this into...

{
  "replacePrefix": "/BIT/",
  "replaceSuffix": "/",
  "replaceTheseStrings": {
    "1": "BLUE",
    "2": "RED",
    "4": "WHITE",
    "9": "PURPLE"
  }
}

....maybe you can help or know anything I could use (extension / scirpt etc). Thank you.

greetz

Link to comment
Share on other sites

Hi NOP,

thanks. Looks a little complicated that AddOn.

Before I found this extension...

https://chrome.google.com/webstore/detail/url-auto-redirector/mckfcfnegaimgcgepikhdnajpkkhdnkn

....using some RegEx but somehow it seems not to work. If I check it right then I have to do this...

My URL...
https://someurl.com/path1/something
----------------------------------------------------


^https://someurl.com/path1/(.*)		to		https://someurl.com/TEST/$1

Now it should just use my redirection URL + the rest after path1/ to add. I'am not sure but I think this extension dosent work right. :( This really sucks.

greetz

  • Like 1
Link to comment
Share on other sites

Us the script https://greasyfork.org/en/scripts/403100-url-replacer-redirector from this place you need to install script editor extension to you browser :
 

Spoiler

Chrome: Tampermonkey or Violentmonkey

Firefox: Greasemonkey, Tampermonkey, or Violentmonkey

Safari: Tampermonkey or Userscripts

Microsoft Edge: Tampermonkey

Opera: Tampermonkey or Violentmonkey

Maxthon: Violentmonkey

After you install one of this extensions above go to the script page again install the script after that stay on the site and press f5 for site reload that is how you get you settings from this script

  • Like 1
Link to comment
Share on other sites

9 hours ago, LCF-AT said:

I'am not sure but I think this extension dosent work right. :( This really sucks.

Here is another option for you...

Redirector which is also on GitHub

This has a much better help system if you get stuck on the syntax and uses wildcard or regex

  • Thanks 1
Link to comment
Share on other sites

@Accede

I can not find the location to enter the JSON prefix. The settings page of TM is same for all scripts.

@NOP

Yeah, that AddOn / Extension looks much better. :) I tried it out and it seems to WORK! Very good. Great find NOP. In case of Brave the notification dosen't work but works in Firefox. Anyway, so long it works its pretty well. Big Bee for you NOP. 🐝

greetz

  • Like 1
Link to comment
Share on other sites

One more question about using RegEx. Somehow it works a little diffrent as normal. On in internet I can find many RegEx online tools I can test on fly but they all do not except the same pattern as in the AddOn.

Online test tool

https://regex101.com/

Now for AddOn you can see some examples.

https://github.com/einaregilsson/Redirector

....like this...

AMP redirect

    Example URL: https://www.google.com/amp/www.example.com/amp/document
    Include pattern: ^(?:https?://)www.(?:google|bing).com/amp/(.*)
    Redirect to: https://$1
    Pattern type: Regular Expression
    Description: AMP is bad: https://80x24.net/post/the-problem-with-amp/

...and now when I wanna test it with online tool I get error on // and / (slashes). Just working when changing slashes to \/ escaped. Why is this working diffrent? Is there any rule for that or have I just to use \/ escaped slashes in Online tools or can I use both etc? Not sure so maybe anyone could explain me. When I have to use just // and when I have to use \/\/ ? Thanks.

greetz

Link to comment
Share on other sites

All special characters in regex when programming should be escqped

The forward slash in some languages is the pattern delimiter and others not so depending what language you are programming in depends whether you need to escape it or not

I use an offline tool and can change the settings for different languages which do vary slightly

Regex.JPG.b9ba7b695cf327fa166c1a73f4736483.JPG

If you use a lot of regex then consider using something similar :)

 

 

Edited by NOP
  • Like 1
Link to comment
Share on other sites

Thanks again NOP. So I see in this extension it seems to handle both un-escaped & escaped variants. :) But good to know. Years ago I used RegEx for a while but I did forget everything about already. :( Now need to lern it new to get some basics.

What is for a tool you do use? Some standalone app?

greetz

Link to comment
Share on other sites

Some tools especially ones that deal with URLs will parse the forward slash for you, I'm assuming that this extension does exactly that

Yes it is a standalone app I use for regex because I do some web scraping using a lot of regex and I find it much easier to create custom regex with a tool like this

The one i use is RegexBuddy :)

  • Like 1
Link to comment
Share on other sites

Ok the tool is not free. :) Do you know some other free tools? I just remember in past I had also one or two RegEx tools I used but I can not find them anymore or remember the name of the tools. Really pitty.

Link to comment
Share on other sites

I haven't tried it but there is a FREE alternative

Expresso

There is a time limit on it but you can get a FREE registration code from them to fully register it

:)

  • Like 1
Link to comment
Share on other sites

Hi again,

I found this old topic...

https://forum.tuts4you.com/topic/40301-looking-for-regular-expression-lib/

...I said I was using 2 tools called ".NET Regular Expression Designer" and "The Regex Coach". This NET app seems not to work so nice like the online tool to highlight all on fly. Do you know any other tool which works and shows all like the online tool?

greetz

Link to comment
Share on other sites

I don't know of any other tool that does what you want

I was in a similar situation when I was learning regex but then found RegexBuuddy and haven't used anything else since because it does everything I want and more

Example link grab from this page...

rb.JPG.4ff0a3e5ef090d97f28765c4c489f960.JPG

As you can see this highlights exactly what you need to see if your regex is working

I did a quick search and the best FREE one seems to Expresso. I have now tried it but IMO it isn't as good and I cant see a highlight option but it does show you the results after clicking the "Run Match" button

 

Edited by NOP
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...