| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 let filters = []; | 89 let filters = []; |
| 90 let selectors = []; | 90 let selectors = []; |
| 91 | 91 |
| 92 let page = details.page; | 92 let page = details.page; |
| 93 let frame = details.frame; | 93 let frame = details.frame; |
| 94 | 94 |
| 95 if (!checkWhitelisted(page, frame)) | 95 if (!checkWhitelisted(page, frame)) |
| 96 { | 96 { |
| 97 let typeMask = RegExpFilter.typeMap[details.type]; | 97 let typeMask = RegExpFilter.typeMap[details.type]; |
| 98 let docDomain = extractHostFromFrame(frame); | 98 let docDomain = extractHostFromFrame(frame); |
| 99 let specificOnly = checkWhitelisted(page, frame, RegExpFilter.typeMap.GENERI
CBLOCK); |
| 99 | 100 |
| 100 // Add a blocking filter for each URL of the element that can be blocked | 101 // Add a blocking filter for each URL of the element that can be blocked |
| 101 for (let url of details.urls) | 102 for (let url of details.urls) |
| 102 { | 103 { |
| 103 let urlObj = new URL(url, details.baseURL); | 104 let urlObj = new URL(url, details.baseURL); |
| 104 url = stringifyURL(urlObj); | 105 url = stringifyURL(urlObj); |
| 105 | 106 |
| 106 let filter = defaultMatcher.whitelist.matchesAny( | 107 let filter = defaultMatcher.whitelist.matchesAny( |
| 107 url, typeMask, docDomain, | 108 url, typeMask, docDomain, |
| 108 isThirdParty(urlObj, docDomain), | 109 isThirdParty(urlObj, docDomain), |
| 109 getKey(page, frame) | 110 getKey(page, frame), specificOnly |
| 110 ); | 111 ); |
| 111 | 112 |
| 112 if (!filter) | 113 if (!filter) |
| 113 { | 114 { |
| 114 let filterText = url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); | 115 let filterText = url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); |
| 115 | 116 |
| 117 if (specificOnly) |
| 118 filterText += "$domain=" + docDomain; |
| 119 |
| 116 if (filters.indexOf(filterText) == -1) | 120 if (filters.indexOf(filterText) == -1) |
| 117 filters.push(filterText); | 121 filters.push(filterText); |
| 118 } | 122 } |
| 119 } | 123 } |
| 120 | 124 |
| 121 // If we couldn't generate any blocking filters, fallback to element hiding | 125 // If we couldn't generate any blocking filters, fallback to element hiding |
| 122 let selectors = []; | 126 let selectors = []; |
| 123 if (filters.length == 0 && !checkWhitelisted(page, frame, RegExpFilter.typeM
ap.ELEMHIDE)) | 127 if (filters.length == 0 && !checkWhitelisted(page, frame, RegExpFilter.typeM
ap.ELEMHIDE)) |
| 124 { | 128 { |
| 125 // Generate CSS selectors based on the element's "id" and "class" attribut
e | 129 // Generate CSS selectors based on the element's "id" and "class" attribut
e |
| (...skipping 15 matching lines...) Expand all Loading... |
| 141 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details
.style) + "]"); | 145 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details
.style) + "]"); |
| 142 | 146 |
| 143 // Add an element hiding filter for each generated CSS selector | 147 // Add an element hiding filter for each generated CSS selector |
| 144 for (let selector of selectors) | 148 for (let selector of selectors) |
| 145 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); | 149 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); |
| 146 } | 150 } |
| 147 } | 151 } |
| 148 | 152 |
| 149 return {filters: filters, selectors: selectors}; | 153 return {filters: filters, selectors: selectors}; |
| 150 }; | 154 }; |
| OLD | NEW |