diff options
author | hackademix | 2018-07-01 01:01:23 +0200 |
---|---|---|
committer | hackademix | 2018-07-01 01:01:23 +0200 |
commit | eceae7187a6f0e9510bc1165f6977256b87f490f (patch) | |
tree | d943f1ec73c09efa70954dcedb55eac82a726148 /TLD/tld_template.js | |
download | noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.tar.gz noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.tar.xz noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.zip |
Initial commit starting at version 10.1.8.3rc4.
Diffstat (limited to 'TLD/tld_template.js')
-rw-r--r-- | TLD/tld_template.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/TLD/tld_template.js b/TLD/tld_template.js new file mode 100644 index 0000000..71906d7 --- /dev/null +++ b/TLD/tld_template.js @@ -0,0 +1,46 @@ +var tld = { + normalize(d) { return d; }, + + isIp(d) { return this._ipRx.test(d); }, + + getDomain(domain) { + if (domain === "localhost" || this.isIp(domain)) return domain; + + domain = this.normalize(domain); + var pos = domain.search(this._tldEx); + if(pos === -1 ) { + pos = domain.search(this._tldRx); + if (pos === -1) { + // TLD not in the public suffix list, fall back to the "one-dot rule" + pos = domain.lastIndexOf("."); + if (pos === -1) { + return ""; + } + } + pos = domain.lastIndexOf(".", pos - 1) + 1; + } else if(domain[pos] == ".") { + ++pos; + } + return pos <= 0 ? domain : domain.substring(pos); + }, + + getPublicSuffix(domain) { + if (this.isIp(domain)) return ""; + + domain = this.normalize(domain); + var pos = domain.search(this._tldEx); + if(pos < 0) { + pos = domain.search(this._tldRx); + if(pos >= 0 && domain[pos] == ".") pos++; + } else { + pos = domain.indexOf(".", pos + 1) + 1; + } + return pos < 0 ? "" : domain.substring(pos); + }, + + _ipRx: /^(?:0\.|[1-9]\d{0,2}\.){3}(?:0|[1-9]\d{0,2})$|:.*:/i, + + _tldRx: /(?:\.|^)%tld_rx%$/ + , + _tldEx: /(?:\.|^)%tld_ex%$/ +} |