LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 /** | 79 /** |
80 * Gets the base domain for the given hostname. | 80 * Gets the base domain for the given hostname. |
81 * | 81 * |
82 * @param {string} hostname | 82 * @param {string} hostname |
83 * @returns {string} | 83 * @returns {string} |
84 */ | 84 */ |
85 function getDomain(hostname) | 85 function getDomain(hostname) |
86 { | 86 { |
87 let slices = []; | 87 let slices = []; |
88 let cutoff = null; | 88 let cutoff = NaN; |
89 | 89 |
90 for (let suffix of suffixes(hostname)) | 90 for (let suffix of suffixes(hostname)) |
91 { | 91 { |
92 slices.push(suffix); | 92 slices.push(suffix); |
93 | 93 |
94 let offset = publicSuffixMap.get(suffix); | 94 let offset = publicSuffixMap.get(suffix); |
95 | 95 |
96 if (typeof offset != "undefined") | 96 if (typeof offset != "undefined") |
97 { | 97 { |
98 cutoff = slices.length - 1 - offset; | 98 cutoff = slices.length - 1 - offset; |
99 break; | 99 break; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 if (cutoff == null) | 103 if (isNaN(cutoff)) |
104 return slices.length > 2 ? slices[slices.length - 2] : hostname; | 104 return slices.length > 2 ? slices[slices.length - 2] : hostname; |
105 | 105 |
106 if (cutoff <= 0) | 106 if (cutoff <= 0) |
107 return hostname; | 107 return hostname; |
108 | 108 |
109 return slices[cutoff]; | 109 return slices[cutoff]; |
110 } | 110 } |
111 | 111 |
112 exports.getDomain = getDomain; | 112 exports.getDomain = getDomain; |
113 | 113 |
(...skipping 18 matching lines...) Expand all Loading... |
132 if (requestHostname == documentHostname) | 132 if (requestHostname == documentHostname) |
133 return false; | 133 return false; |
134 | 134 |
135 if (!isDomain(requestHostname) || !isDomain(documentHostname)) | 135 if (!isDomain(requestHostname) || !isDomain(documentHostname)) |
136 return true; | 136 return true; |
137 | 137 |
138 return getDomain(requestHostname) != getDomain(documentHostname); | 138 return getDomain(requestHostname) != getDomain(documentHostname); |
139 } | 139 } |
140 | 140 |
141 exports.isThirdParty = isThirdParty; | 141 exports.isThirdParty = isThirdParty; |
LEFT | RIGHT |