Index: devtools-panel.js |
diff --git a/devtools-panel.js b/devtools-panel.js |
index 85068dd5c1ed8a02309a7370b841b84f7e134df6..68cb324023fbd7667404ddd02523c8c19c0100cd 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\.)?/, "||"); |
@@ -120,6 +122,40 @@ function createRecord(request, filter, template) |
return row; |
} |
+function shouldFilterRow(row, query) |
+{ |
+ var filtered = true; |
Thomas Greiner
2016/11/29 12:17:06
Detail: Unused variable.
kzar
2016/11/30 14:50:18
Whoops well spotted, done.
|
+ var elementsToSearch = [ |
+ row.getElementsByClassName("url"), |
+ row.getElementsByClassName("filter"), |
+ row.getElementsByClassName("origin"), |
+ row.getElementsByClassName("type") |
+ ]; |
+ |
+ for (var elements of elementsToSearch) |
Thomas Greiner
2016/11/29 12:17:07
Detail: For consistency and to reduce the potentia
kzar
2016/11/30 14:50:20
Done.
Thomas Greiner
2016/11/30 15:40:16
Thanks!
|
+ 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"); |
@@ -146,7 +182,10 @@ document.addEventListener("DOMContentLoaded", function() |
switch (message.type) |
{ |
case "add-record": |
- table.appendChild(createRecord(message.request, message.filter, template)); |
+ var record = createRecord(message.request, message.filter, template); |
+ if (lastFilterQuery && shouldFilterRow(record, lastFilterQuery)) |
+ record.classList.add("filtered-by-search"); |
+ table.appendChild(record); |
break; |
case "update-record": |
Thomas Greiner
2016/11/29 12:17:07
Since you're adapting "add-record" to ensure that
kzar
2016/11/30 14:50:18
Done.
|
@@ -169,4 +208,18 @@ document.addEventListener("DOMContentLoaded", function() |
break; |
} |
}); |
+ window.addEventListener("message", function(event) |
Thomas Greiner
2016/11/29 12:17:07
Detail: Separating those two listeners by a newlin
kzar
2016/11/30 14:50:20
Done.
|
+ { |
+ switch(event.data.type) |
+ { |
+ case "performSearch": |
+ performSearch(table, event.data.queryString); |
+ lastFilterQuery = event.data.queryString; |
+ break; |
+ case "cancelSearch": |
+ cancelSearch(table); |
+ lastFilterQuery = null; |
+ break; |
+ } |
+ }); |
}, false); |