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 var abpSelectorRegExp = /\[-abp-selector=(["'])(.+)\1\]/; |
| 930 |
929 /** | 931 /** |
930 * Creates an element hiding filter from a pre-parsed text representation | 932 * Creates an element hiding filter from a pre-parsed text representation |
931 * | 933 * |
932 * @param {string} text same as in Filter() | 934 * @param {string} text same as in Filter() |
933 * @param {string} domain | 935 * @param {string} domain |
934 * domain part of the text representation (can be empty) | 936 * domain part of the text representation (can be empty) |
935 * @param {boolean} isException exception rule indicator | 937 * @param {boolean} isException exception rule indicator |
936 * @param {string} tagName tag name part (can be empty) | 938 * @param {string} tagName tag name part (can be empty) |
937 * @param {string} attrRules attribute matching rules (can be empty) | 939 * @param {string} attrRules attribute matching rules (can be empty) |
938 * @param {string} selector raw CSS selector (can be empty) | 940 * @param {string} selector raw CSS selector (can be empty) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 | 983 |
982 // We don't allow ElemHide filters which have any empty domains. | 984 // We don't allow ElemHide filters which have any empty domains. |
983 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that | 985 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that |
984 // changes this must be changed too. | 986 // changes this must be changed too. |
985 if (domain && /(^|,)~?(,|$)/.test(domain)) | 987 if (domain && /(^|,)~?(,|$)/.test(domain)) |
986 return new InvalidFilter(text, "filter_invalid_domain"); | 988 return new InvalidFilter(text, "filter_invalid_domain"); |
987 | 989 |
988 if (isException) | 990 if (isException) |
989 return new ElemHideException(text, domain, selector); | 991 return new ElemHideException(text, domain, selector); |
990 | 992 |
991 if (selector.indexOf("[-abp-properties=") != -1) | 993 if ((selector.indexOf("[-abp-properties=") != -1) || |
| 994 (selector.indexOf("[-abp-selector=") != -1)) |
992 { | 995 { |
993 // Element hiding emulation filters are inefficient so we need to make sure | 996 // Element hiding emulation filters are inefficient so we need to make sure |
994 // that they're only applied if they specify active domains | 997 // that they're only applied if they specify active domains |
995 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) | 998 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) |
996 return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); | 999 return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); |
997 | 1000 |
| 1001 var match = abpSelectorRegExp.exec(selector); |
| 1002 if (match) |
| 1003 { |
| 1004 var prefix = selector.substr(0, match.index).trim(); |
| 1005 var suffix = selector.substr(match.index + match[0].length).trim(); |
| 1006 var unwrappedSelector = prefix + match[2] + suffix; |
| 1007 return new ElemHideEmulationFilter(text, domain, unwrappedSelector); |
| 1008 } |
998 return new ElemHideEmulationFilter(text, domain, selector); | 1009 return new ElemHideEmulationFilter(text, domain, selector); |
999 } | 1010 } |
1000 | 1011 |
1001 return new ElemHideFilter(text, domain, selector); | 1012 return new ElemHideFilter(text, domain, selector); |
1002 }; | 1013 }; |
1003 | 1014 |
1004 /** | 1015 /** |
1005 * Class for element hiding filters | 1016 * Class for element hiding filters |
1006 * @param {string} text see Filter() | 1017 * @param {string} text see Filter() |
1007 * @param {string} domains see ElemHideBase() | 1018 * @param {string} domains see ElemHideBase() |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 */ | 1058 */ |
1048 function ElemHideEmulationFilter(text, domains, selector) | 1059 function ElemHideEmulationFilter(text, domains, selector) |
1049 { | 1060 { |
1050 ElemHideBase.call(this, text, domains, selector); | 1061 ElemHideBase.call(this, text, domains, selector); |
1051 } | 1062 } |
1052 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1063 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
1053 | 1064 |
1054 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1065 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
1055 type: "elemhideemulation" | 1066 type: "elemhideemulation" |
1056 }); | 1067 }); |
OLD | NEW |