fluks / redirect-link

A browser addon to redirect a link to somewhere else.
GNU General Public License v3.0
22 stars 2 forks source link

Add a regular expression format? #11

Closed fluks closed 4 years ago

fluks commented 5 years ago

It would be nice to be able to redirect Google AMP links to the regular page.

Here's an AMP URL:

https://www.google.com/amp/s/www.foxnews.com/us/kentucky-sheriff-suspends-law-enforcement-over-lack-of-funding-folks-lock-your-doors.amp

URL I want:

https://www.foxnews.com/us/kentucky-sheriff-suspends-law-enforcement-over-lack-of-funding-folks-lock-your-doors

Format could be %r[REGEX] and if more than one match is returned, i.e. capturing groups are used, replace the format with the second one.

Regex to get the wanted example URL:

wholeURL.match(/^(?:https:\/\/www.google.com\/amp\/s\/)(.*)(?:\.amp)$/)
// or, note that groups starting with ?: are ignored
%r[^(?:https:\/\/www.google.com\/amp\/s\/)(.*)(?:\.amp)$]
// Returns: [ 'https://www.google.com/amp/s/www.foxnews.com/us/kentucky-sheriff-suspends-law-enforcement-over-lack-of-funding-folks-lock-your-doors.amp',
// 'www.foxnews.com/us/kentucky-sheriff-suspends-law-enforcement-over-lack-of-funding-folks-lock-your-doors',
// index: 0,
// input: 'https://www.google.com/amp/s/www.foxnews.com/us/kentucky-sheriff-suspends-law-enforcement-over-lack-of-funding-folks-lock-your-doors.amp' ]

What about character sets (e.g. [a-z])? Escape them somehow?

fluks commented 4 years ago

Implemented in 4c4e327.