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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 return { | 71 return { |
72 text: filter.text, | 72 text: filter.text, |
73 whitelisted: filter instanceof WhitelistFilter, | 73 whitelisted: filter instanceof WhitelistFilter, |
74 userDefined, | 74 userDefined, |
75 subscription: subscriptionTitle | 75 subscription: subscriptionTitle |
76 }; | 76 }; |
77 } | 77 } |
78 | 78 |
79 function hasRecord(panel, request, filter) | 79 function hasRecord(panel, request, filter) |
80 { | 80 { |
81 for (let record of panel.records) | 81 return panel.records.some(record => |
82 { | 82 record.request.url == request.url && |
83 if (record.request.url != request.url || | 83 record.request.docDomain == request.docDomain && |
84 record.request.docDomain != request.docDomain) | 84 |
85 continue; | 85 // Ignore partial (e.g. ELEMHIDE) whitelisting if there is already |
86 | 86 // a DOCUMENT exception which disables all means of blocking. |
87 if (record.request.type == "DOCUMENT") | 87 (record.request.type == "DOCUMENT" ? |
88 { | 88 nonRequestTypes.includes(request.type) : |
89 // Ignore partial (e.g. ELEMHIDE) whitelisting if there is already | 89 record.request.type == request.type) && |
90 // a DOCUMENT exception which disables all means of blocking. | |
91 if (!nonRequestTypes.includes(request.type)) | |
92 continue; | |
93 } | |
94 else if (record.request.type != request.type) | |
95 continue; | |
96 | 90 |
97 // Matched element hiding filters don't relate to a particular request, | 91 // Matched element hiding filters don't relate to a particular request, |
98 // so we also have to match the CSS selector in order to distinguish them. | 92 // so we have to compare the selector in order to avoid duplicates. |
99 if ((record.filter && record.filter.selector) == | 93 (record.filter && record.filter.selector) == (filter && filter.selector) |
100 (filter && filter.selector)) | 94 ); |
101 return true; | |
102 } | |
103 | |
104 return false; | |
105 } | 95 } |
106 | 96 |
107 function addRecord(panel, request, filter) | 97 function addRecord(panel, request, filter) |
108 { | 98 { |
109 if (!hasRecord(panel, request, filter)) | 99 if (!hasRecord(panel, request, filter)) |
110 { | 100 { |
111 panel.port.postMessage({ | 101 panel.port.postMessage({ |
112 type: "add-record", | 102 type: "add-record", |
113 request, | 103 request, |
114 filter: getFilterInfo(filter) | 104 filter: getFilterInfo(filter) |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 panels[inspectedTabId] = {port: newPort, records: []}; | 377 panels[inspectedTabId] = {port: newPort, records: []}; |
388 }); | 378 }); |
389 | 379 |
390 port.on("devtools.traceElemHide", (message, sender) => | 380 port.on("devtools.traceElemHide", (message, sender) => |
391 { | 381 { |
392 logHiddenElements( | 382 logHiddenElements( |
393 sender.page, message.selectors, | 383 sender.page, message.selectors, |
394 extractHostFromFrame(sender.frame) | 384 extractHostFromFrame(sender.frame) |
395 ); | 385 ); |
396 }); | 386 }); |
LEFT | RIGHT |