Walid I checked out your code and have a remark and a few suggestions.
First, I see the logic checks for the hostname being anywhere in the URL, so this means a link like https://external.tld/page?domain=flarum.tld
will not open externally. You could use the URL
javascript object to parse the href
value and compare if the .host
or .origin
values match instead of String.contains()
.
Second I saw some redundant code. The check for /admin
should not be necessary because you only add the code to the forum
bundle. Same for element instanceof HTMLAnchorElement
, I'm pretty sure it's redundant because the query selector a
already enforces it.
And a note to users of the extension, the way it's implemented will take precedence over anything defined by another extension. Any extension defining a target
or rel
attribute at the TextFormatter level will be overridden. The extension will also strip the rel=ugc
attribute that Flarum sets by default on user-generated content.