feddit.de is missing.
Comment on I wrote hacky tampermonkey script to fix Lemmy instance links. Any advice?
Andy@programming.dev 1 year ago
I just posted this on the post you linked, but yeah I am hardcoding a list of instances into my solution. Here’s my comment, copied:
I’m using the Firefox addon Redirector, and one of my rules there redirects community links using regex. I keep adding to the pattern as I encounter more instances. Currently it’s:
Pattern: https://(lemdro\.id|lemmy\.run|beehaw\.org|lemmy\.ml|sh\.itjust\.works|lemmy\.fmhy\.ml|lemmy\.dbzer0\.com|lemmy\.world|sopuli\.xyz|lemmy\.kde\.social|lemmygrad\.ml|mander\.xyz|lemmy\.ca|zerobytes\.monster)/c/(.*)
Redirect to: https://programming.dev/c/$2@$1
Turun@feddit.de 1 year ago
TerrorBite@meow.social 1 year ago
@Andy @BeanCounter Given how many of these start with "Lemmy" you could simplify this to:
`https://(lemmy\.(?:run|(?:fmhy\.)?ml|dbzer0\.com|world|kde\.social|ca)|lemmygrad\.ml|lemdro\.id|beehaw\.org|sh\.itjust\.works|(?:sopuli|mander)\.xyz|zerobytes\.monster)/c/(.*)`
Or just assume that anything matching `https://(lemmy\.[^/]+)/c/(.*)` is a Lemmy server, which will probably be correct.
ezchili@iusearchlinux.fyi 1 year ago
Never use regex on URLs, make a list of hostnames and use the browser’s URL api to extract hostnames then match against the list
Andy@programming.dev 1 year ago
Can you provide an example URL that breaks this solution?
ezchili@iusearchlinux.fyi 1 year ago
Sure!
user:pw@lemdro.id:80 is a valid url to lemdro.id and should match but will not
maliciouswebsite.to/?q=http://lemdro.id will match but should not
Andy@programming.dev 1 year ago
Well that one:
No, it does not match.
AFAICT, this solution is working properly, but if you can find a URL that breaks it, please let me know.