I want to check if I am in certain domain, like this (in manifest.json for chrome extensions):
"content_scripts": [
{
"matches": ["*://certain.site/*"],
"js": ["some.js"]
}
But it seems like there are only dirty ways in javascript, like .split("/") which I don't want to use. Is there a clean way to do it?
You can use the URL interface for that. Like:
const currentUrl = new URL(window.location.href);
Now you can get the things like path and hostname from the currentUrl, like currentUrl.pathname.
To get only the file name you now can do:
currentUrl.pathname.split('/').pop()
you get detail of URL
console.log(location);
get current url
console.log(location.href);