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; |
| 128 var elementsToSearch = [ |
| 129 row.getElementsByClassName("url"), |
| 130 row.getElementsByClassName("filter"), |
| 131 row.getElementsByClassName("origin") |
| 132 ]; |
| 133 |
| 134 for (var elements of elementsToSearch) |
| 135 for (var element of elements) |
| 136 if (element.innerText.search(query) != -1) |
| 137 return false; |
| 138 return true; |
| 139 } |
| 140 |
| 141 function performSearch(table, query) |
| 142 { |
| 143 for (var row of table.rows) |
| 144 { |
| 145 if (shouldFilterRow(row, query)) |
| 146 row.classList.add("filtered-by-search"); |
| 147 else |
| 148 row.classList.remove("filtered-by-search"); |
| 149 } |
| 150 } |
| 151 |
| 152 function cancelSearch(table) |
| 153 { |
| 154 for (var row of table.rows) |
| 155 row.classList.remove("filtered-by-search"); |
| 156 } |
| 157 |
123 document.addEventListener("DOMContentLoaded", function() | 158 document.addEventListener("DOMContentLoaded", function() |
124 { | 159 { |
125 var container = document.getElementById("items"); | 160 var container = document.getElementById("items"); |
126 var table = container.querySelector("tbody"); | 161 var table = container.querySelector("tbody"); |
127 var template = document.querySelector("template").content.firstElementChild; | 162 var template = document.querySelector("template").content.firstElementChild; |
128 | 163 |
129 document.getElementById("reload").addEventListener("click", function() | 164 document.getElementById("reload").addEventListener("click", function() |
130 { | 165 { |
131 ext.devtools.inspectedWindow.reload(); | 166 ext.devtools.inspectedWindow.reload(); |
132 }, false); | 167 }, false); |
133 | 168 |
134 document.getElementById("filter-state").addEventListener("change", function(ev
ent) | 169 document.getElementById("filter-state").addEventListener("change", function(ev
ent) |
135 { | 170 { |
136 container.dataset.filterState = event.target.value; | 171 container.dataset.filterState = event.target.value; |
137 }, false); | 172 }, false); |
138 | 173 |
139 document.getElementById("filter-type").addEventListener("change", function(eve
nt) | 174 document.getElementById("filter-type").addEventListener("change", function(eve
nt) |
140 { | 175 { |
141 container.dataset.filterType = event.target.value; | 176 container.dataset.filterType = event.target.value; |
142 }, false); | 177 }, false); |
143 | 178 |
144 ext.onMessage.addListener(function(message) | 179 ext.onMessage.addListener(function(message) |
145 { | 180 { |
146 switch (message.type) | 181 switch (message.type) |
147 { | 182 { |
148 case "add-record": | 183 case "add-record": |
149 table.appendChild(createRecord(message.request, message.filter, template
)); | 184 var record = createRecord(message.request, message.filter, template); |
| 185 if (lastFilterQuery && shouldFilterRow(record, lastFilterQuery)) |
| 186 record.add("filtered-by-search"); |
| 187 table.appendChild(record); |
150 break; | 188 break; |
151 | 189 |
152 case "update-record": | 190 case "update-record": |
153 var oldRow = table.getElementsByTagName("tr")[message.index]; | 191 var oldRow = table.getElementsByTagName("tr")[message.index]; |
154 var newRow = createRecord(message.request, message.filter, template); | 192 var newRow = createRecord(message.request, message.filter, template); |
155 oldRow.parentNode.replaceChild(newRow, oldRow); | 193 oldRow.parentNode.replaceChild(newRow, oldRow); |
156 newRow.classList.add("changed"); | 194 newRow.classList.add("changed"); |
157 container.classList.add("has-changes"); | 195 container.classList.add("has-changes"); |
158 break; | 196 break; |
159 | 197 |
160 case "remove-record": | 198 case "remove-record": |
161 var row = table.getElementsByTagName("tr")[message.index]; | 199 var row = table.getElementsByTagName("tr")[message.index]; |
162 row.parentNode.removeChild(row); | 200 row.parentNode.removeChild(row); |
163 container.classList.add("has-changes"); | 201 container.classList.add("has-changes"); |
164 break; | 202 break; |
165 | 203 |
166 case "reset": | 204 case "reset": |
167 table.innerHTML = ""; | 205 table.innerHTML = ""; |
168 container.classList.remove("has-changes"); | 206 container.classList.remove("has-changes"); |
169 break; | 207 break; |
170 } | 208 } |
171 }); | 209 }); |
| 210 window.addEventListener("message", function(event) |
| 211 { |
| 212 switch(event.data.type) |
| 213 { |
| 214 case "performSearch": |
| 215 performSearch(table, event.data.queryString); |
| 216 lastFilterQuery = event.data.queryString; |
| 217 break; |
| 218 case "cancelSearch": |
| 219 cancelSearch(table); |
| 220 lastFilterQuery = null; |
| 221 break; |
| 222 } |
| 223 }); |
172 }, false); | 224 }, false); |
OLD | NEW |