1var url = window.location.href;
2var domain = url.replace('http://','').replace('https://','').split(/[/?#]/)[0];
3
1const url = 'http://www.youtube.com/watch?v=ClkQA2Lb_iE';
2const { hostname } = new URL(url);
3
4console.assert(hostname === 'www.youtube.com'); // true