OLD | NEW |
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 * @type {string} | 919 * @type {string} |
920 */ | 920 */ |
921 selectorDomain: null, | 921 selectorDomain: null, |
922 /** | 922 /** |
923 * CSS selector for the HTML elements that should be hidden | 923 * CSS selector for the HTML elements that should be hidden |
924 * @type {string} | 924 * @type {string} |
925 */ | 925 */ |
926 selector: null | 926 selector: null |
927 }); | 927 }); |
928 | 928 |
| 929 const abpSelectorRegExp = /\[-abp-selector=(["'])(.+)\1\]/; |
| 930 const abpPropertySelectorRegExp = /\[-abp-properties=(["'])([^"']+)\1\]/; |
| 931 |
929 /** | 932 /** |
930 * Creates an element hiding filter from a pre-parsed text representation | 933 * Creates an element hiding filter from a pre-parsed text representation |
931 * | 934 * |
932 * @param {string} text same as in Filter() | 935 * @param {string} text same as in Filter() |
933 * @param {string} domain | 936 * @param {string} domain |
934 * domain part of the text representation (can be empty) | 937 * domain part of the text representation (can be empty) |
935 * @param {boolean} isException exception rule indicator | 938 * @param {boolean} isException exception rule indicator |
936 * @param {string} tagName tag name part (can be empty) | 939 * @param {string} tagName tag name part (can be empty) |
937 * @param {string} attrRules attribute matching rules (can be empty) | 940 * @param {string} attrRules attribute matching rules (can be empty) |
938 * @param {string} selector raw CSS selector (can be empty) | 941 * @param {string} selector raw CSS selector (can be empty) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 else | 981 else |
979 return new InvalidFilter(text, "filter_elemhide_nocriteria"); | 982 return new InvalidFilter(text, "filter_elemhide_nocriteria"); |
980 } | 983 } |
981 | 984 |
982 // We don't allow ElemHide filters which have any empty domains. | 985 // We don't allow ElemHide filters which have any empty domains. |
983 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that | 986 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that |
984 // changes this must be changed too. | 987 // changes this must be changed too. |
985 if (domain && /(^|,)~?(,|$)/.test(domain)) | 988 if (domain && /(^|,)~?(,|$)/.test(domain)) |
986 return new InvalidFilter(text, "filter_invalid_domain"); | 989 return new InvalidFilter(text, "filter_invalid_domain"); |
987 | 990 |
| 991 let isHideEmulation = false; |
| 992 if ((selector.indexOf("[-abp-properties=") != -1) || |
| 993 (selector.indexOf("[-abp-selector=") != -1)) |
| 994 { |
| 995 isHideEmulation = true; |
| 996 |
| 997 // Element hiding emulation filters are inefficient so we need to make sure |
| 998 // that they're only applied if they specify active domains |
| 999 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) |
| 1000 return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); |
| 1001 |
| 1002 let match = abpSelectorRegExp.exec(selector); |
| 1003 if (match) |
| 1004 { |
| 1005 let prefix = selector.substr(0, match.index); |
| 1006 let suffix = selector.substr(match.index + match[0].length); |
| 1007 selector = prefix + match[2] + suffix; |
| 1008 } |
| 1009 match = abpPropertySelectorRegExp.exec(selector); |
| 1010 if (match) |
| 1011 { |
| 1012 let prefix = selector.substr(0, match.index); |
| 1013 let suffix = selector.substr(match.index + match[0].length); |
| 1014 selector = prefix + ":-abp-properties(" + |
| 1015 match[1] + match[2] + match[1] + ")" + suffix; |
| 1016 } |
| 1017 } |
| 1018 |
988 if (isException) | 1019 if (isException) |
989 return new ElemHideException(text, domain, selector); | 1020 return new ElemHideException(text, domain, selector); |
990 | 1021 |
991 if (selector.indexOf("[-abp-properties=") != -1) | 1022 if (isHideEmulation) |
992 { | 1023 { |
993 // Element hiding emulation filters are inefficient so we need to make sure | 1024 // Element hiding emulation filters are inefficient so we need to make sure |
994 // that they're only applied if they specify active domains | 1025 // that they're only applied if they specify active domains |
995 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) | 1026 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) |
996 return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); | 1027 return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); |
997 | 1028 |
998 return new ElemHideEmulationFilter(text, domain, selector); | 1029 return new ElemHideEmulationFilter(text, domain, selector); |
999 } | 1030 } |
1000 | 1031 |
1001 return new ElemHideFilter(text, domain, selector); | 1032 return new ElemHideFilter(text, domain, selector); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 */ | 1078 */ |
1048 function ElemHideEmulationFilter(text, domains, selector) | 1079 function ElemHideEmulationFilter(text, domains, selector) |
1049 { | 1080 { |
1050 ElemHideBase.call(this, text, domains, selector); | 1081 ElemHideBase.call(this, text, domains, selector); |
1051 } | 1082 } |
1052 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1083 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
1053 | 1084 |
1054 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1085 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
1055 type: "elemhideemulation" | 1086 type: "elemhideemulation" |
1056 }); | 1087 }); |
OLD | NEW |