Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 * hiding filters: {filters: [...], selectors: [...]} | 81 * hiding filters: {filters: [...], selectors: [...]} |
82 */ | 82 */ |
83 exports.composeFilters = function(details) | 83 exports.composeFilters = function(details) |
84 { | 84 { |
85 let filters = []; | 85 let filters = []; |
86 let selectors = []; | 86 let selectors = []; |
87 | 87 |
88 let page = details.page; | 88 let page = details.page; |
89 let frame = details.frame; | 89 let frame = details.frame; |
90 | 90 |
91 if (!isFrameWhitelisted(page, frame, "DOCUMENT")) | 91 if (!isFrameWhitelisted(page, frame, RegExpFilter.typeMap.DOCUMENT)) |
92 { | 92 { |
93 let typeMask = RegExpFilter.typeMap[details.type]; | |
93 let docDomain = extractHostFromFrame(frame); | 94 let docDomain = extractHostFromFrame(frame); |
94 | 95 |
95 // Add a blocking filter for each URL of the element that can be blocked | 96 // Add a blocking filter for each URL of the element that can be blocked |
96 for (let url of details.urls) | 97 for (let url of details.urls) |
97 { | 98 { |
98 let urlObj = new URL(url, details.baseURL); | 99 let urlObj = new URL(url, details.baseURL); |
99 url = stringifyURL(urlObj); | 100 url = stringifyURL(urlObj); |
100 | 101 |
101 let filter = defaultMatcher.whitelist.matchesAny( | 102 let filter = defaultMatcher.whitelist.matchesAny( |
102 url, RegExpFilter.toTypeMask(details.type), docDomain, | 103 url, typeMask, docDomain, |
Sebastian Noack
2015/07/09 15:28:52
Same here:
let docDomain = extractHostFromFrame
kzar
2015/07/12 14:28:01
Done.
| |
103 isThirdParty(urlObj, docDomain), | 104 isThirdParty(urlObj, docDomain), |
104 getKey(page, frame) | 105 getKey(page, frame) |
105 ); | 106 ); |
106 | 107 |
107 if (!filter) | 108 if (!filter) |
108 { | 109 { |
109 let filterText = url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); | 110 let filterText = url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); |
110 | 111 |
111 if (filters.indexOf(filterText) == -1) | 112 if (filters.indexOf(filterText) == -1) |
112 filters.push(filterText); | 113 filters.push(filterText); |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
116 // If we couldn't generate any blocking filters, fallback to element hiding | 117 // If we couldn't generate any blocking filters, fallback to element hiding |
117 let selectors = []; | 118 let selectors = []; |
118 if (filters.length == 0 && !isFrameWhitelisted(page, frame, "ELEMHIDE")) | 119 if (filters.length == 0 && !isFrameWhitelisted(page, frame, RegExpFilter.typ eMap.ELEMHIDE)) |
119 { | 120 { |
120 // Generate CSS selectors based on the element's "id" and "class" attribut e | 121 // Generate CSS selectors based on the element's "id" and "class" attribut e |
121 if (details.id) | 122 if (details.id) |
122 selectors.push("#" + escapeCSS(details.id)); | 123 selectors.push("#" + escapeCSS(details.id)); |
123 if (details.classes.length > 0) | 124 if (details.classes.length > 0) |
124 selectors.push(details.classes.map(c => "." + escapeCSS(c)).join("")); | 125 selectors.push(details.classes.map(c => "." + escapeCSS(c)).join("")); |
125 | 126 |
126 // If there is a "src" attribute, specifiying a URL that we can't block, | 127 // If there is a "src" attribute, specifiying a URL that we can't block, |
127 // generate a CSS selector matching the "src" attribute | 128 // generate a CSS selector matching the "src" attribute |
128 if (details.src) | 129 if (details.src) |
129 selectors.push(escapeCSS(details.tagName) + "[src=" + quoteCSS(details.s rc) + "]"); | 130 selectors.push(escapeCSS(details.tagName) + "[src=" + quoteCSS(details.s rc) + "]"); |
130 | 131 |
131 // As last resort, if there is a "style" attribute, and we couldn't genera te | 132 // As last resort, if there is a "style" attribute, and we couldn't genera te |
132 // any filters so far, generate a CSS selector matching the "style" attrib ute | 133 // any filters so far, generate a CSS selector matching the "style" attrib ute |
133 if (details.style && selectors.length == 0 && filters.length == 0) | 134 if (details.style && selectors.length == 0 && filters.length == 0) |
134 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details .style) + "]"); | 135 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details .style) + "]"); |
135 | 136 |
136 // Add an element hiding filter for each generated CSS selector | 137 // Add an element hiding filter for each generated CSS selector |
137 for (let selector of selectors) | 138 for (let selector of selectors) |
138 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); | 139 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); |
139 } | 140 } |
140 } | 141 } |
141 | 142 |
142 return {filters: filters, selectors: selectors}; | 143 return {filters: filters, selectors: selectors}; |
143 }; | 144 }; |
LEFT | RIGHT |