| Left: | ||
| Right: |
| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 toString() | 74 toString() |
| 75 { | 75 { |
| 76 return this.text; | 76 return this.text; |
| 77 } | 77 } |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * Cache for known filters, maps string representation to filter objects. | 81 * Cache for known filters, maps string representation to filter objects. |
| 82 * @type {Object} | 82 * @type {Object} |
| 83 */ | 83 */ |
| 84 Filter.knownFilters = Object.create(null); | 84 Filter.knownFilters = new Map(); |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * Regular expression that element hiding filters should match | 87 * Regular expression that element hiding filters should match |
| 88 * @type {RegExp} | 88 * @type {RegExp} |
| 89 */ | 89 */ |
| 90 Filter.elemhideRegExp = /^([^/*|@"!]*?)#([@?])?#(.+)$/; | 90 Filter.elemhideRegExp = /^([^/*|@"!]*?)#([@?])?#(.+)$/; |
| 91 /** | 91 /** |
| 92 * Regular expression that RegExp filters specified as RegExps should match | 92 * Regular expression that RegExp filters specified as RegExps should match |
| 93 * @type {RegExp} | 93 * @type {RegExp} |
| 94 */ | 94 */ |
| 95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/; | 95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/; |
| 96 /** | 96 /** |
| 97 * Regular expression that options on a RegExp filter should match | 97 * Regular expression that options on a RegExp filter should match |
| 98 * @type {RegExp} | 98 * @type {RegExp} |
| 99 */ | 99 */ |
| 100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^,\s]+)?)*)$/; | 100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^,\s]+)?)*)$/; |
| 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 if (text in Filter.knownFilters) | 111 if (Filter.knownFilters.has(text)) |
| 112 return Filter.knownFilters[text]; | 112 return Filter.knownFilters.get(text); |
|
Wladimir Palant
2017/09/20 08:59:10
It makes little sense to have two calls here. You
sergei
2017/09/20 09:22:40
I also thought about it because there are no `unde
| |
| 113 | 113 |
| 114 let ret; | 114 let ret; |
| 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 ret = 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 ret = new CommentFilter(text); |
| 136 else | 136 else |
| 137 ret = RegExpFilter.fromText(text); | 137 ret = RegExpFilter.fromText(text); |
| 138 | 138 |
| 139 Filter.knownFilters[ret.text] = ret; | 139 Filter.knownFilters.set(ret.text, ret); |
| 140 return ret; | 140 return ret; |
| 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) |
| (...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1020 */ | 1020 */ |
| 1021 function ElemHideEmulationFilter(text, domains, selector) | 1021 function ElemHideEmulationFilter(text, domains, selector) |
| 1022 { | 1022 { |
| 1023 ElemHideBase.call(this, text, domains, selector); | 1023 ElemHideBase.call(this, text, domains, selector); |
| 1024 } | 1024 } |
| 1025 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1025 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
| 1026 | 1026 |
| 1027 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1027 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
| 1028 type: "elemhideemulation" | 1028 type: "elemhideemulation" |
| 1029 }); | 1029 }); |
| OLD | NEW |