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-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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 if (filter.userDefined) | 112 if (filter.userDefined) |
113 actionWrapper.appendChild(createActionButton( | 113 actionWrapper.appendChild(createActionButton( |
114 "remove", "Remove rule", filter.text | 114 "remove", "Remove rule", filter.text |
115 )); | 115 )); |
116 } | 116 } |
117 else | 117 else |
118 actionWrapper.appendChild(createActionButton( | 118 actionWrapper.appendChild(createActionButton( |
119 "add", "Block item", generateFilter(request, request.specificOnly) | 119 "add", "Block item", generateFilter(request, request.specificOnly) |
120 )); | 120 )); |
121 | 121 |
| 122 if (lastFilterQuery && shouldFilterRow(row, lastFilterQuery)) |
| 123 row.classList.add("filtered-by-search"); |
| 124 |
122 return row; | 125 return row; |
123 } | 126 } |
124 | 127 |
125 function shouldFilterRow(row, query) | 128 function shouldFilterRow(row, query) |
126 { | 129 { |
127 var filtered = true; | |
128 var elementsToSearch = [ | 130 var elementsToSearch = [ |
129 row.getElementsByClassName("url"), | 131 row.getElementsByClassName("url"), |
130 row.getElementsByClassName("filter"), | 132 row.getElementsByClassName("filter"), |
131 row.getElementsByClassName("origin") | 133 row.getElementsByClassName("origin"), |
| 134 row.getElementsByClassName("type") |
132 ]; | 135 ]; |
133 | 136 |
134 for (var elements of elementsToSearch) | 137 for (var elements of elementsToSearch) |
| 138 { |
135 for (var element of elements) | 139 for (var element of elements) |
| 140 { |
136 if (element.innerText.search(query) != -1) | 141 if (element.innerText.search(query) != -1) |
137 return false; | 142 return false; |
| 143 } |
| 144 } |
138 return true; | 145 return true; |
139 } | 146 } |
140 | 147 |
141 function performSearch(table, query) | 148 function performSearch(table, query) |
142 { | 149 { |
143 for (var row of table.rows) | 150 for (var row of table.rows) |
144 { | 151 { |
145 if (shouldFilterRow(row, query)) | 152 if (shouldFilterRow(row, query)) |
146 row.classList.add("filtered-by-search"); | 153 row.classList.add("filtered-by-search"); |
147 else | 154 else |
(...skipping 26 matching lines...) Expand all Loading... |
174 document.getElementById("filter-type").addEventListener("change", function(eve
nt) | 181 document.getElementById("filter-type").addEventListener("change", function(eve
nt) |
175 { | 182 { |
176 container.dataset.filterType = event.target.value; | 183 container.dataset.filterType = event.target.value; |
177 }, false); | 184 }, false); |
178 | 185 |
179 ext.onMessage.addListener(function(message) | 186 ext.onMessage.addListener(function(message) |
180 { | 187 { |
181 switch (message.type) | 188 switch (message.type) |
182 { | 189 { |
183 case "add-record": | 190 case "add-record": |
184 var record = createRecord(message.request, message.filter, template); | 191 table.appendChild(createRecord(message.request, message.filter, template
)); |
185 if (lastFilterQuery && shouldFilterRow(record, lastFilterQuery)) | |
186 record.add("filtered-by-search"); | |
187 table.appendChild(record); | |
188 break; | 192 break; |
189 | 193 |
190 case "update-record": | 194 case "update-record": |
191 var oldRow = table.getElementsByTagName("tr")[message.index]; | 195 var oldRow = table.getElementsByTagName("tr")[message.index]; |
192 var newRow = createRecord(message.request, message.filter, template); | 196 var newRow = createRecord(message.request, message.filter, template); |
193 oldRow.parentNode.replaceChild(newRow, oldRow); | 197 oldRow.parentNode.replaceChild(newRow, oldRow); |
194 newRow.classList.add("changed"); | 198 newRow.classList.add("changed"); |
195 container.classList.add("has-changes"); | 199 container.classList.add("has-changes"); |
196 break; | 200 break; |
197 | 201 |
198 case "remove-record": | 202 case "remove-record": |
199 var row = table.getElementsByTagName("tr")[message.index]; | 203 var row = table.getElementsByTagName("tr")[message.index]; |
200 row.parentNode.removeChild(row); | 204 row.parentNode.removeChild(row); |
201 container.classList.add("has-changes"); | 205 container.classList.add("has-changes"); |
202 break; | 206 break; |
203 | 207 |
204 case "reset": | 208 case "reset": |
205 table.innerHTML = ""; | 209 table.innerHTML = ""; |
206 container.classList.remove("has-changes"); | 210 container.classList.remove("has-changes"); |
207 break; | 211 break; |
208 } | 212 } |
209 }); | 213 }); |
| 214 |
210 window.addEventListener("message", function(event) | 215 window.addEventListener("message", function(event) |
211 { | 216 { |
212 switch(event.data.type) | 217 switch(event.data.type) |
213 { | 218 { |
214 case "performSearch": | 219 case "performSearch": |
215 performSearch(table, event.data.queryString); | 220 performSearch(table, event.data.queryString); |
216 lastFilterQuery = event.data.queryString; | 221 lastFilterQuery = event.data.queryString; |
217 break; | 222 break; |
218 case "cancelSearch": | 223 case "cancelSearch": |
219 cancelSearch(table); | 224 cancelSearch(table); |
220 lastFilterQuery = null; | 225 lastFilterQuery = null; |
221 break; | 226 break; |
222 } | 227 } |
223 }); | 228 }); |
224 }, false); | 229 }, false); |
LEFT | RIGHT |