forked from sblask-webextensions/webextension-skip-redirect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psl.js
41 lines (31 loc) · 1.03 KB
/
psl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* global pslrules */
const psl = (function(root) { // eslint-disable-line no-unused-vars
if (typeof pslrules === "undefined") {
pslrules = require("./pslrules"); // eslint-disable-line no-global-assign,no-unused-vars
}
function getDomain(hostname, previousHead=undefined) {
if (!hostname) {
return undefined;
}
if (pslrules.EXCEPTION_ENTRIES.has(hostname)) {
return hostname;
}
const dotIndex = hostname.indexOf(".");
if (dotIndex == -1) {
return undefined;
}
const head = hostname.slice(0, dotIndex);
const rest = hostname.slice(dotIndex + 1);
if (pslrules.WILDCARD_ENTRIES.has(rest) && previousHead) {
return [previousHead, head, rest].join(".");
}
if (pslrules.NORMAL_ENTRIES.has(rest)) {
return [head, rest].join(".");
}
return getDomain(rest, head);
}
root.getDomain = getDomain;
return {
getDomain: getDomain,
};
})(this);