I see your point regarding global scope. But personally, I’ve never encountered an issue with it. And it’s kinda nice not to have to import fetch every time you need it.
Regarding subdomains, if you’ll humor my curiosity: What’s the use case? I also wonder what an API for this might look like.
If I understand correctly, you want to check the current domain (eg. w3schools) against api.w3schools and www.youtube, and return true for the first and false for the second (or the other way around)
Then technically it’s possible without string splitting:
I see your point regarding global scope. But personally, I’ve never encountered an issue with it. And it’s kinda nice not to have to import
fetchevery time you need it.Regarding subdomains, if you’ll humor my curiosity: What’s the use case? I also wonder what an API for this might look like.
const {domain, subdomains, rootDomain} = new URL('https://wikipedia.org/') // 'wikipedia.org', [], 'wikipedia.org' const {domain, subdomains, rootDomain} = new URL('https://foo.bar.baz.net/') // 'foo.bar.baz.net', ['foo.bar.baz.net', 'bar.baz.net'], 'baz.net'A userscript over links for debugging purposes, that should ignore links to the same domain (www.w3schools vs campus.w3schools vs www.youtube).
Btw, it’s funny how support.mozilla and some standards-teaching-sites are some of the worst offenders of web standards.
Edit: how to stop this auto-linking?
If I understand correctly, you want to check the current domain (eg. w3schools) against api.w3schools and www.youtube, and return true for the first and false for the second (or the other way around)
Then technically it’s possible without string splitting:
const href = 'retrieved-from-the-anchor-element'; (new URL(href, location.href).hostname).endsWith(location.hostname)Well, the whole web is basically “let’s go, make it work somehow”. Thanks for your effort!