mastodon-redirector icon indicating copy to clipboard operation
mastodon-redirector copied to clipboard

Get the correct username from the page URL, rather than extracting it from HTML

Open nanos opened this issue 3 years ago • 3 comments

That should be both more reliable, and stable (particularly when mastodon instances use custom themes, or a new mastodon version changes the HTML).

It also addresses https://github.com/bramus/mastodon-profile-redirect/issues/3: The reason this one isn't working, is because hachyderm doesn't always have the meta[property="profile:username"] element on the page.

I have left the previous mechanism to extract the username from the HTML in place, because it might be useful for instances that have changed the URL scheme (e.g. by removing the @ from the url) although I personally haven't seen any.

nanos avatar Nov 25 '22 07:11 nanos

That actually was my first approach, but doesn’t work for instances that run on a subdomain.

For example: the profile URL for @[email protected] on their server is https://fediverse.zachleat.com/@zachleat. The instance runs on fedivers.zachleat.com which is a subdomain of zachleat.com. By parsing the data from the URL, their profile username would become @[email protected] which is wrong. It’s @[email protected]. This value can be found in the meta tag (if present).

Maybe this step could be included, but as fallback? First try the meta tag, then fall back to other possible locations.

bramus avatar Nov 25 '22 09:11 bramus

LOL, yes, funnily enough I run my own instance on a subdomain, so should’ve definitely realised that, but I’ve set up an http redirect so it still works for me.

Will adjust the PR to do the checks the other way around: meta tag first, URL as fallback

nanos avatar Nov 25 '22 09:11 nanos

I've updated that now 👍

nanos avatar Nov 25 '22 11:11 nanos