Notes

Code base

从 URL 字符串中提取主机名

function getHostName(url) {
    var match = url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i);
    if (match != null && match.length > 2 && typeof match[2] === 'string' && match[2].length > 0) {
    return match[2];
    }
    else {
        return null;
    }
}

Reference

Parsing Hostname and Domain from a Url with Javascript

从 URL 字符串中提取域名

function getDomain(url) {
    var hostName = getHostName(url);
    var domain = hostName;
    
    if (hostName != null) {
        var parts = hostName.split('.').reverse();
        
        if (parts != null && parts.length > 1) {
            domain = parts[1] + '.' + parts[0];
                
            if (hostName.toLowerCase().indexOf('.co.uk') != -1 && parts.length > 2) {
              domain = parts[2] + '.' + domain;
            }
        }
    }
    
    return domain;
}

Reference

Parsing Hostname and Domain from a Url with Javascript

检测键盘输入回车

// 在 onKeyDown 事件中

if (event.key === 'Enter') {
  this.handleClick();
}