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