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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 if (filter.userDefined) | 112 if (filter.userDefined) |
111 actionWrapper.appendChild(createActionButton( | 113 actionWrapper.appendChild(createActionButton( |
112 "remove", "Remove rule", filter.text | 114 "remove", "Remove rule", filter.text |
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 |
| 122 if (lastFilterQuery && shouldFilterRow(row, lastFilterQuery)) |
| 123 row.classList.add("filtered-by-search"); |
| 124 |
120 return row; | 125 return row; |
121 } | 126 } |
122 | 127 |
| 128 function shouldFilterRow(row, query) |
| 129 { |
| 130 var elementsToSearch = [ |
| 131 row.getElementsByClassName("url"), |
| 132 row.getElementsByClassName("filter"), |
| 133 row.getElementsByClassName("origin"), |
| 134 row.getElementsByClassName("type") |
| 135 ]; |
| 136 |
| 137 for (var elements of elementsToSearch) |
| 138 { |
| 139 for (var element of elements) |
| 140 { |
| 141 if (element.innerText.search(query) != -1) |
| 142 return false; |
| 143 } |
| 144 } |
| 145 return true; |
| 146 } |
| 147 |
| 148 function performSearch(table, query) |
| 149 { |
| 150 for (var row of table.rows) |
| 151 { |
| 152 if (shouldFilterRow(row, query)) |
| 153 row.classList.add("filtered-by-search"); |
| 154 else |
| 155 row.classList.remove("filtered-by-search"); |
| 156 } |
| 157 } |
| 158 |
| 159 function cancelSearch(table) |
| 160 { |
| 161 for (var row of table.rows) |
| 162 row.classList.remove("filtered-by-search"); |
| 163 } |
| 164 |
123 document.addEventListener("DOMContentLoaded", function() | 165 document.addEventListener("DOMContentLoaded", function() |
124 { | 166 { |
125 var container = document.getElementById("items"); | 167 var container = document.getElementById("items"); |
126 var table = container.querySelector("tbody"); | 168 var table = container.querySelector("tbody"); |
127 var template = document.querySelector("template").content.firstElementChild; | 169 var template = document.querySelector("template").content.firstElementChild; |
128 | 170 |
129 document.getElementById("reload").addEventListener("click", function() | 171 document.getElementById("reload").addEventListener("click", function() |
130 { | 172 { |
131 ext.devtools.inspectedWindow.reload(); | 173 ext.devtools.inspectedWindow.reload(); |
132 }, false); | 174 }, false); |
(...skipping 29 matching lines...) Expand all Loading... |
162 row.parentNode.removeChild(row); | 204 row.parentNode.removeChild(row); |
163 container.classList.add("has-changes"); | 205 container.classList.add("has-changes"); |
164 break; | 206 break; |
165 | 207 |
166 case "reset": | 208 case "reset": |
167 table.innerHTML = ""; | 209 table.innerHTML = ""; |
168 container.classList.remove("has-changes"); | 210 container.classList.remove("has-changes"); |
169 break; | 211 break; |
170 } | 212 } |
171 }); | 213 }); |
| 214 |
| 215 window.addEventListener("message", function(event) |
| 216 { |
| 217 switch(event.data.type) |
| 218 { |
| 219 case "performSearch": |
| 220 performSearch(table, event.data.queryString); |
| 221 lastFilterQuery = event.data.queryString; |
| 222 break; |
| 223 case "cancelSearch": |
| 224 cancelSearch(table); |
| 225 lastFilterQuery = null; |
| 226 break; |
| 227 } |
| 228 }); |
172 }, false); | 229 }, false); |
OLD | NEW |