OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 /** |
| 19 * Map of features supported by element hiding emulation filters |
| 20 */ |
| 21 var elemHideEmulationFeatureMap = { |
| 22 PROPERTY_SELECTOR: 1, |
| 23 HAS_PSEUDO_CLASS: 2 |
| 24 }; |
| 25 |
| 26 /** |
| 27 * Converts filter text into regular expression string |
| 28 * @param {String} text as in Filter() |
| 29 * @return {String} regular expression representation of filter text |
| 30 */ |
| 31 function filterToRegExp(text) |
| 32 { |
| 33 return text |
| 34 // remove multiple wildcards |
| 35 .replace(/\*+/g, "*") |
| 36 // remove anchors following separator placeholder |
| 37 .replace(/\^\|$/, "^") |
| 38 // escape special symbols |
| 39 .replace(/\W/g, "\\$&") |
| 40 // replace wildcards by .* |
| 41 .replace(/\\\*/g, ".*") |
| 42 // process separator placeholders (all ANSI characters but alphanumeric |
| 43 // characters and _%.-) |
| 44 .replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x6
0\\x7B-\\x7F]|$)") |
| 45 // process extended anchor at expression start |
| 46 .replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") |
| 47 // process anchor at expression start |
| 48 .replace(/^\\\|/, "^") |
| 49 // process anchor at expression end |
| 50 .replace(/\\\|$/, "$") |
| 51 // remove leading wildcards |
| 52 .replace(/^(\.\*)/, "") |
| 53 // remove trailing wildcards |
| 54 .replace(/(\.\*)$/, ""); |
| 55 } |
| 56 |
| 57 if (typeof exports != "undefined") |
| 58 { |
| 59 exports.filterToRegExp = filterToRegExp; |
| 60 exports.elemHideEmulationFeatureMap = elemHideEmulationFeatureMap; |
| 61 } |
OLD | NEW |