| 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-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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * Creates a filter of correct type from its text representation - does the | 103 * Creates a filter of correct type from its text representation - does the |
| 104 * basic parsing and calls the right constructor then. | 104 * basic parsing and calls the right constructor then. |
| 105 * | 105 * |
| 106 * @param {string} text as in Filter() | 106 * @param {string} text as in Filter() |
| 107 * @return {Filter} | 107 * @return {Filter} |
| 108 */ | 108 */ |
| 109 Filter.fromText = function(text) | 109 Filter.fromText = function(text) |
| 110 { | 110 { |
| 111 let ret = Filter.knownFilters.get(text); | 111 let filter = Filter.knownFilters.get(text); |
| 112 if (ret) | 112 if (filter) |
| 113 return ret; | 113 return filter; |
| 114 | 114 |
| 115 let match = (text.includes("#") ? Filter.elemhideRegExp.exec(text) : null); | 115 let match = (text.includes("#") ? Filter.elemhideRegExp.exec(text) : null); |
| 116 if (match) | 116 if (match) |
| 117 { | 117 { |
| 118 let propsMatch; | 118 let propsMatch; |
| 119 if (!match[2] && | 119 if (!match[2] && |
| 120 (propsMatch = /\[-abp-properties=(["'])([^"']+)\1\]/.exec(match[3]))) | 120 (propsMatch = /\[-abp-properties=(["'])([^"']+)\1\]/.exec(match[3]))) |
| 121 { | 121 { |
| 122 // This is legacy CSS properties syntax, convert to current syntax | 122 // This is legacy CSS properties syntax, convert to current syntax |
| 123 let prefix = match[3].substr(0, propsMatch.index); | 123 let prefix = match[3].substr(0, propsMatch.index); |
| 124 let expression = propsMatch[2]; | 124 let expression = propsMatch[2]; |
| 125 let suffix = match[3].substr(propsMatch.index + propsMatch[0].length); | 125 let suffix = match[3].substr(propsMatch.index + propsMatch[0].length); |
| 126 return Filter.fromText(`${match[1]}#?#` + | 126 return Filter.fromText(`${match[1]}#?#` + |
| 127 `${prefix}:-abp-properties(${expression})${suffix}`); | 127 `${prefix}:-abp-properties(${expression})${suffix}`); |
| 128 } | 128 } |
| 129 | 129 |
| 130 ret = ElemHideBase.fromText( | 130 filter = ElemHideBase.fromText( |
| 131 text, match[1], match[2], match[3] | 131 text, match[1], match[2], match[3] |
| 132 ); | 132 ); |
| 133 } | 133 } |
| 134 else if (text[0] == "!") | 134 else if (text[0] == "!") |
| 135 ret = new CommentFilter(text); | 135 filter = new CommentFilter(text); |
| 136 else | 136 else |
| 137 ret = RegExpFilter.fromText(text); | 137 filter = RegExpFilter.fromText(text); |
| 138 | 138 |
| 139 Filter.knownFilters.set(ret.text, ret); | 139 Filter.knownFilters.set(filter.text, filter); |
| 140 return ret; | 140 return filter; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 /** | 143 /** |
| 144 * Deserializes a filter | 144 * Deserializes a filter |
| 145 * | 145 * |
| 146 * @param {Object} obj map of serialized properties and their values | 146 * @param {Object} obj map of serialized properties and their values |
| 147 * @return {Filter} filter or null if the filter couldn't be created | 147 * @return {Filter} filter or null if the filter couldn't be created |
| 148 */ | 148 */ |
| 149 Filter.fromObject = function(obj) | 149 Filter.fromObject = function(obj) |
| 150 { | 150 { |
| 151 let ret = Filter.fromText(obj.text); | 151 let filter = Filter.fromText(obj.text); |
| 152 if (ret instanceof ActiveFilter) | 152 if (filter instanceof ActiveFilter) |
| 153 { | 153 { |
| 154 if ("disabled" in obj) | 154 if ("disabled" in obj) |
| 155 ret._disabled = (obj.disabled == "true"); | 155 filter._disabled = (obj.disabled == "true"); |
| 156 if ("hitCount" in obj) | 156 if ("hitCount" in obj) |
| 157 ret._hitCount = parseInt(obj.hitCount, 10) || 0; | 157 filter._hitCount = parseInt(obj.hitCount, 10) || 0; |
| 158 if ("lastHit" in obj) | 158 if ("lastHit" in obj) |
| 159 ret._lastHit = parseInt(obj.lastHit, 10) || 0; | 159 filter._lastHit = parseInt(obj.lastHit, 10) || 0; |
| 160 } | 160 } |
| 161 return ret; | 161 return filter; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 /** | 164 /** |
| 165 * Removes unnecessary whitespaces from filter text, will only return null if | 165 * Removes unnecessary whitespaces from filter text, will only return null if |
| 166 * the input parameter is null. | 166 * the input parameter is null. |
| 167 * @param {string} text | 167 * @param {string} text |
| 168 * @return {string} | 168 * @return {string} |
| 169 */ | 169 */ |
| 170 Filter.normalize = function(text) | 170 Filter.normalize = function(text) |
| 171 { | 171 { |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 */ | 1021 */ |
| 1022 function ElemHideEmulationFilter(text, domains, selector) | 1022 function ElemHideEmulationFilter(text, domains, selector) |
| 1023 { | 1023 { |
| 1024 ElemHideBase.call(this, text, domains, selector); | 1024 ElemHideBase.call(this, text, domains, selector); |
| 1025 } | 1025 } |
| 1026 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1026 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
| 1027 | 1027 |
| 1028 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1028 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
| 1029 type: "elemhideemulation" | 1029 type: "elemhideemulation" |
| 1030 }); | 1030 }); |
| OLD | NEW |