Left: | ||
Right: |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 var lastFilterQuery = null; | |
21 | |
20 function generateFilter(request, domainSpecific) | 22 function generateFilter(request, domainSpecific) |
21 { | 23 { |
22 var filter = request.url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); | 24 var filter = request.url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); |
23 var options = []; | 25 var options = []; |
24 | 26 |
25 if (request.type == "POPUP") | 27 if (request.type == "POPUP") |
26 { | 28 { |
27 options.push("popup"); | 29 options.push("popup"); |
28 | 30 |
29 if (request.url == "about:blank") | 31 if (request.url == "about:blank") |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 )); | 115 )); |
114 } | 116 } |
115 else | 117 else |
116 actionWrapper.appendChild(createActionButton( | 118 actionWrapper.appendChild(createActionButton( |
117 "add", "Block item", generateFilter(request, request.specificOnly) | 119 "add", "Block item", generateFilter(request, request.specificOnly) |
118 )); | 120 )); |
119 | 121 |
120 return row; | 122 return row; |
121 } | 123 } |
122 | 124 |
125 function shouldFilterRow(row, query) | |
126 { | |
127 var filtered = true; | |
Thomas Greiner
2016/11/29 12:17:06
Detail: Unused variable.
kzar
2016/11/30 14:50:18
Whoops well spotted, done.
| |
128 var elementsToSearch = [ | |
129 row.getElementsByClassName("url"), | |
130 row.getElementsByClassName("filter"), | |
131 row.getElementsByClassName("origin"), | |
132 row.getElementsByClassName("type") | |
133 ]; | |
134 | |
135 for (var elements of elementsToSearch) | |
Thomas Greiner
2016/11/29 12:17:07
Detail: For consistency and to reduce the potentia
kzar
2016/11/30 14:50:20
Done.
Thomas Greiner
2016/11/30 15:40:16
Thanks!
| |
136 for (var element of elements) | |
137 if (element.innerText.search(query) != -1) | |
138 return false; | |
139 return true; | |
140 } | |
141 | |
142 function performSearch(table, query) | |
143 { | |
144 for (var row of table.rows) | |
145 { | |
146 if (shouldFilterRow(row, query)) | |
147 row.classList.add("filtered-by-search"); | |
148 else | |
149 row.classList.remove("filtered-by-search"); | |
150 } | |
151 } | |
152 | |
153 function cancelSearch(table) | |
154 { | |
155 for (var row of table.rows) | |
156 row.classList.remove("filtered-by-search"); | |
157 } | |
158 | |
123 document.addEventListener("DOMContentLoaded", function() | 159 document.addEventListener("DOMContentLoaded", function() |
124 { | 160 { |
125 var container = document.getElementById("items"); | 161 var container = document.getElementById("items"); |
126 var table = container.querySelector("tbody"); | 162 var table = container.querySelector("tbody"); |
127 var template = document.querySelector("template").content.firstElementChild; | 163 var template = document.querySelector("template").content.firstElementChild; |
128 | 164 |
129 document.getElementById("reload").addEventListener("click", function() | 165 document.getElementById("reload").addEventListener("click", function() |
130 { | 166 { |
131 ext.devtools.inspectedWindow.reload(); | 167 ext.devtools.inspectedWindow.reload(); |
132 }, false); | 168 }, false); |
133 | 169 |
134 document.getElementById("filter-state").addEventListener("change", function(ev ent) | 170 document.getElementById("filter-state").addEventListener("change", function(ev ent) |
135 { | 171 { |
136 container.dataset.filterState = event.target.value; | 172 container.dataset.filterState = event.target.value; |
137 }, false); | 173 }, false); |
138 | 174 |
139 document.getElementById("filter-type").addEventListener("change", function(eve nt) | 175 document.getElementById("filter-type").addEventListener("change", function(eve nt) |
140 { | 176 { |
141 container.dataset.filterType = event.target.value; | 177 container.dataset.filterType = event.target.value; |
142 }, false); | 178 }, false); |
143 | 179 |
144 ext.onMessage.addListener(function(message) | 180 ext.onMessage.addListener(function(message) |
145 { | 181 { |
146 switch (message.type) | 182 switch (message.type) |
147 { | 183 { |
148 case "add-record": | 184 case "add-record": |
149 table.appendChild(createRecord(message.request, message.filter, template )); | 185 var record = createRecord(message.request, message.filter, template); |
186 if (lastFilterQuery && shouldFilterRow(record, lastFilterQuery)) | |
187 record.classList.add("filtered-by-search"); | |
188 table.appendChild(record); | |
150 break; | 189 break; |
151 | 190 |
152 case "update-record": | 191 case "update-record": |
Thomas Greiner
2016/11/29 12:17:07
Since you're adapting "add-record" to ensure that
kzar
2016/11/30 14:50:18
Done.
| |
153 var oldRow = table.getElementsByTagName("tr")[message.index]; | 192 var oldRow = table.getElementsByTagName("tr")[message.index]; |
154 var newRow = createRecord(message.request, message.filter, template); | 193 var newRow = createRecord(message.request, message.filter, template); |
155 oldRow.parentNode.replaceChild(newRow, oldRow); | 194 oldRow.parentNode.replaceChild(newRow, oldRow); |
156 newRow.classList.add("changed"); | 195 newRow.classList.add("changed"); |
157 container.classList.add("has-changes"); | 196 container.classList.add("has-changes"); |
158 break; | 197 break; |
159 | 198 |
160 case "remove-record": | 199 case "remove-record": |
161 var row = table.getElementsByTagName("tr")[message.index]; | 200 var row = table.getElementsByTagName("tr")[message.index]; |
162 row.parentNode.removeChild(row); | 201 row.parentNode.removeChild(row); |
163 container.classList.add("has-changes"); | 202 container.classList.add("has-changes"); |
164 break; | 203 break; |
165 | 204 |
166 case "reset": | 205 case "reset": |
167 table.innerHTML = ""; | 206 table.innerHTML = ""; |
168 container.classList.remove("has-changes"); | 207 container.classList.remove("has-changes"); |
169 break; | 208 break; |
170 } | 209 } |
171 }); | 210 }); |
211 window.addEventListener("message", function(event) | |
Thomas Greiner
2016/11/29 12:17:07
Detail: Separating those two listeners by a newlin
kzar
2016/11/30 14:50:20
Done.
| |
212 { | |
213 switch(event.data.type) | |
214 { | |
215 case "performSearch": | |
216 performSearch(table, event.data.queryString); | |
217 lastFilterQuery = event.data.queryString; | |
218 break; | |
219 case "cancelSearch": | |
220 cancelSearch(table); | |
221 lastFilterQuery = null; | |
222 break; | |
223 } | |
224 }); | |
172 }, false); | 225 }, false); |
OLD | NEW |