Index: devtools-panel.js |
diff --git a/devtools-panel.js b/devtools-panel.js |
index 85068dd5c1ed8a02309a7370b841b84f7e134df6..d9d89619bb4ff15f678b642a8f2025103e3dd58c 100644 |
--- a/devtools-panel.js |
+++ b/devtools-panel.js |
@@ -17,6 +17,8 @@ |
"use strict"; |
+var lastFilterQuery = null; |
+ |
function generateFilter(request, domainSpecific) |
{ |
var filter = request.url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); |
@@ -117,9 +119,49 @@ function createRecord(request, filter, template) |
"add", "Block item", generateFilter(request, request.specificOnly) |
)); |
+ if (lastFilterQuery && shouldFilterRow(row, lastFilterQuery)) |
+ row.classList.add("filtered-by-search"); |
+ |
return row; |
} |
+function shouldFilterRow(row, query) |
+{ |
+ var elementsToSearch = [ |
+ row.getElementsByClassName("url"), |
+ row.getElementsByClassName("filter"), |
+ row.getElementsByClassName("origin"), |
+ row.getElementsByClassName("type") |
+ ]; |
+ |
+ for (var elements of elementsToSearch) |
+ { |
+ for (var element of elements) |
+ { |
+ if (element.innerText.search(query) != -1) |
+ return false; |
+ } |
+ } |
+ return true; |
+} |
+ |
+function performSearch(table, query) |
+{ |
+ for (var row of table.rows) |
+ { |
+ if (shouldFilterRow(row, query)) |
+ row.classList.add("filtered-by-search"); |
+ else |
+ row.classList.remove("filtered-by-search"); |
+ } |
+} |
+ |
+function cancelSearch(table) |
+{ |
+ for (var row of table.rows) |
+ row.classList.remove("filtered-by-search"); |
+} |
+ |
document.addEventListener("DOMContentLoaded", function() |
{ |
var container = document.getElementById("items"); |
@@ -169,4 +211,19 @@ document.addEventListener("DOMContentLoaded", function() |
break; |
} |
}); |
+ |
+ window.addEventListener("message", function(event) |
+ { |
+ switch(event.data.type) |
+ { |
+ case "performSearch": |
+ performSearch(table, event.data.queryString); |
+ lastFilterQuery = event.data.queryString; |
+ break; |
+ case "cancelSearch": |
+ cancelSearch(table); |
+ lastFilterQuery = null; |
+ break; |
+ } |
+ }); |
}, false); |