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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 let match = (text.indexOf("#") >= 0 ? Filter.elemhideRegExp.exec(text) : null)
; | 102 let match = (text.indexOf("#") >= 0 ? Filter.elemhideRegExp.exec(text) : null)
; |
103 if (match) | 103 if (match) |
104 ret = ElemHideBase.fromText(text, match[1], match[2], match[3], match[4], ma
tch[5]); | 104 ret = ElemHideBase.fromText(text, match[1], match[2], match[3], match[4], ma
tch[5]); |
105 else if (text[0] == "!") | 105 else if (text[0] == "!") |
106 ret = new CommentFilter(text); | 106 ret = new CommentFilter(text); |
107 else | 107 else |
108 ret = RegExpFilter.fromText(text); | 108 ret = RegExpFilter.fromText(text); |
109 | 109 |
110 Filter.knownFilters[ret.text] = ret; | 110 Filter.knownFilters[ret.text] = ret; |
111 return ret; | 111 return ret; |
112 } | 112 }; |
113 | 113 |
114 /** | 114 /** |
115 * Deserializes a filter | 115 * Deserializes a filter |
116 * | 116 * |
117 * @param {Object} obj map of serialized properties and their values | 117 * @param {Object} obj map of serialized properties and their values |
118 * @return {Filter} filter or null if the filter couldn't be created | 118 * @return {Filter} filter or null if the filter couldn't be created |
119 */ | 119 */ |
120 Filter.fromObject = function(obj) | 120 Filter.fromObject = function(obj) |
121 { | 121 { |
122 let ret = Filter.fromText(obj.text); | 122 let ret = Filter.fromText(obj.text); |
123 if (ret instanceof ActiveFilter) | 123 if (ret instanceof ActiveFilter) |
124 { | 124 { |
125 if ("disabled" in obj) | 125 if ("disabled" in obj) |
126 ret._disabled = (obj.disabled == "true"); | 126 ret._disabled = (obj.disabled == "true"); |
127 if ("hitCount" in obj) | 127 if ("hitCount" in obj) |
128 ret._hitCount = parseInt(obj.hitCount) || 0; | 128 ret._hitCount = parseInt(obj.hitCount) || 0; |
129 if ("lastHit" in obj) | 129 if ("lastHit" in obj) |
130 ret._lastHit = parseInt(obj.lastHit) || 0; | 130 ret._lastHit = parseInt(obj.lastHit) || 0; |
131 } | 131 } |
132 return ret; | 132 return ret; |
133 } | 133 }; |
134 | 134 |
135 /** | 135 /** |
136 * Removes unnecessary whitespaces from filter text, will only return null if | 136 * Removes unnecessary whitespaces from filter text, will only return null if |
137 * the input parameter is null. | 137 * the input parameter is null. |
138 */ | 138 */ |
139 Filter.normalize = function(/**String*/ text) /**String*/ | 139 Filter.normalize = function(/**String*/ text) /**String*/ |
140 { | 140 { |
141 if (!text) | 141 if (!text) |
142 return text; | 142 return text; |
143 | 143 |
144 // Remove line breaks and such | 144 // Remove line breaks and such |
145 text = text.replace(/[^\S ]/g, ""); | 145 text = text.replace(/[^\S ]/g, ""); |
146 | 146 |
147 if (/^\s*!/.test(text)) | 147 if (/^\s*!/.test(text)) |
148 { | 148 { |
149 // Don't remove spaces inside comments | 149 // Don't remove spaces inside comments |
150 return text.trim(); | 150 return text.trim(); |
151 } | 151 } |
152 else if (Filter.elemhideRegExp.test(text)) | 152 else if (Filter.elemhideRegExp.test(text)) |
153 { | 153 { |
154 // Special treatment for element hiding filters, right side is allowed to co
ntain spaces | 154 // Special treatment for element hiding filters, right side is allowed to co
ntain spaces |
155 let [, domain, separator, selector] = /^(.*?)(#\@?#?)(.*)$/.exec(text); | 155 let [, domain, separator, selector] = /^(.*?)(#\@?#?)(.*)$/.exec(text); |
156 return domain.replace(/\s/g, "") + separator + selector.trim(); | 156 return domain.replace(/\s/g, "") + separator + selector.trim(); |
157 } | 157 } |
158 else | 158 else |
159 return text.replace(/\s/g, ""); | 159 return text.replace(/\s/g, ""); |
160 } | 160 }; |
161 | 161 |
162 /** | 162 /** |
163 * Class for invalid filters | 163 * Class for invalid filters |
164 * @param {String} text see Filter() | 164 * @param {String} text see Filter() |
165 * @param {String} reason Reason why this filter is invalid | 165 * @param {String} reason Reason why this filter is invalid |
166 * @constructor | 166 * @constructor |
167 * @augments Filter | 167 * @augments Filter |
168 */ | 168 */ |
169 function InvalidFilter(text, reason) | 169 function InvalidFilter(text, reason) |
170 { | 170 { |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 { | 718 { |
719 if (blocking) | 719 if (blocking) |
720 return new BlockingFilter(origText, text, contentType, matchCase, domains,
thirdParty, sitekeys, collapse); | 720 return new BlockingFilter(origText, text, contentType, matchCase, domains,
thirdParty, sitekeys, collapse); |
721 else | 721 else |
722 return new WhitelistFilter(origText, text, contentType, matchCase, domains
, thirdParty, sitekeys); | 722 return new WhitelistFilter(origText, text, contentType, matchCase, domains
, thirdParty, sitekeys); |
723 } | 723 } |
724 catch (e) | 724 catch (e) |
725 { | 725 { |
726 return new InvalidFilter(origText, e); | 726 return new InvalidFilter(origText, e); |
727 } | 727 } |
728 } | 728 }; |
729 | 729 |
730 /** | 730 /** |
731 * Maps type strings like "SCRIPT" or "OBJECT" to bit masks | 731 * Maps type strings like "SCRIPT" or "OBJECT" to bit masks |
732 */ | 732 */ |
733 RegExpFilter.typeMap = { | 733 RegExpFilter.typeMap = { |
734 OTHER: 1, | 734 OTHER: 1, |
735 SCRIPT: 2, | 735 SCRIPT: 2, |
736 IMAGE: 4, | 736 IMAGE: 4, |
737 STYLESHEET: 8, | 737 STYLESHEET: 8, |
738 OBJECT: 16, | 738 OBJECT: 16, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 */ | 801 */ |
802 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, th
irdParty, sitekeys) | 802 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, th
irdParty, sitekeys) |
803 { | 803 { |
804 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t
hirdParty, sitekeys); | 804 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t
hirdParty, sitekeys); |
805 } | 805 } |
806 exports.WhitelistFilter = WhitelistFilter; | 806 exports.WhitelistFilter = WhitelistFilter; |
807 | 807 |
808 WhitelistFilter.prototype = | 808 WhitelistFilter.prototype = |
809 { | 809 { |
810 __proto__: RegExpFilter.prototype | 810 __proto__: RegExpFilter.prototype |
811 } | 811 }; |
812 | 812 |
813 /** | 813 /** |
814 * Base class for element hiding filters | 814 * Base class for element hiding filters |
815 * @param {String} text see Filter() | 815 * @param {String} text see Filter() |
816 * @param {String} [domains] Host names or domains the filter should be restrict
ed to | 816 * @param {String} [domains] Host names or domains the filter should be restrict
ed to |
817 * @param {String} selector CSS selector for the HTML elements that should be
hidden | 817 * @param {String} selector CSS selector for the HTML elements that should be
hidden |
818 * @constructor | 818 * @constructor |
819 * @augments ActiveFilter | 819 * @augments ActiveFilter |
820 */ | 820 */ |
821 function ElemHideBase(text, domains, selector) | 821 function ElemHideBase(text, domains, selector) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 else | 901 else |
902 { | 902 { |
903 let {Utils} = require("utils"); | 903 let {Utils} = require("utils"); |
904 return new InvalidFilter(text, Utils.getString("filter_elemhide_nocriteria
")); | 904 return new InvalidFilter(text, Utils.getString("filter_elemhide_nocriteria
")); |
905 } | 905 } |
906 } | 906 } |
907 if (isException) | 907 if (isException) |
908 return new ElemHideException(text, domain, selector); | 908 return new ElemHideException(text, domain, selector); |
909 else | 909 else |
910 return new ElemHideFilter(text, domain, selector); | 910 return new ElemHideFilter(text, domain, selector); |
911 } | 911 }; |
912 | 912 |
913 /** | 913 /** |
914 * Class for element hiding filters | 914 * Class for element hiding filters |
915 * @param {String} text see Filter() | 915 * @param {String} text see Filter() |
916 * @param {String} domains see ElemHideBase() | 916 * @param {String} domains see ElemHideBase() |
917 * @param {String} selector see ElemHideBase() | 917 * @param {String} selector see ElemHideBase() |
918 * @constructor | 918 * @constructor |
919 * @augments ElemHideBase | 919 * @augments ElemHideBase |
920 */ | 920 */ |
921 function ElemHideFilter(text, domains, selector) | 921 function ElemHideFilter(text, domains, selector) |
(...skipping 18 matching lines...) Expand all Loading... |
940 function ElemHideException(text, domains, selector) | 940 function ElemHideException(text, domains, selector) |
941 { | 941 { |
942 ElemHideBase.call(this, text, domains, selector); | 942 ElemHideBase.call(this, text, domains, selector); |
943 } | 943 } |
944 exports.ElemHideException = ElemHideException; | 944 exports.ElemHideException = ElemHideException; |
945 | 945 |
946 ElemHideException.prototype = | 946 ElemHideException.prototype = |
947 { | 947 { |
948 __proto__: ElemHideBase.prototype | 948 __proto__: ElemHideBase.prototype |
949 }; | 949 }; |
OLD | NEW |