From 9cc437755a27a49d273d402304486429d30e4b36 Mon Sep 17 00:00:00 2001 From: Heath123 Date: Tue, 13 Apr 2021 13:10:29 +0100 Subject: [PATCH] Fix filtering again --- html/mainPage/js/filteringLogic.js | 6 ++++-- html/mainPage/js/main.js | 7 ++++--- html/mainPage/js/packetDom.js | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/html/mainPage/js/filteringLogic.js b/html/mainPage/js/filteringLogic.js index ab8a418..c7cb93b 100644 --- a/html/mainPage/js/filteringLogic.js +++ b/html/mainPage/js/filteringLogic.js @@ -1,9 +1,10 @@ -exports.packetFilteredByFilterBox = function (packet, filter, hiddenPackets, inverseFiltering, regexFilter) { +exports.packetFilteredByFilterBox = function (packet, filter, hiddenPackets, inverseFiltering, regexFilter, + sharedVars) { if (hiddenPackets[packet.direction].includes(packet.meta.name)) { return true } - if (filter === '') { + if (sharedVars.lastFilter === '') { return false } @@ -14,6 +15,7 @@ exports.packetFilteredByFilterBox = function (packet, filter, hiddenPackets, inv filter = new RegExp(sharedVars.lastFilter) } catch (err) { // TODO: handle + console.error(err) filter = new RegExp("") } } diff --git a/html/mainPage/js/main.js b/html/mainPage/js/main.js index 788b145..0ee3a77 100644 --- a/html/mainPage/js/main.js +++ b/html/mainPage/js/main.js @@ -80,16 +80,17 @@ function updateFiltering () { regex = new RegExp(sharedVars.lastFilter) } catch (err) { // TODO: handle + console.error(err) regex = new RegExp("") } } sharedVars.allPacketsHTML.forEach(function (item, index, array) { - if (sharedVars.lastFilter === '' || - !filteringLogic.packetFilteredByFilterBox(sharedVars.allPackets[index], + if (!filteringLogic.packetFilteredByFilterBox(sharedVars.allPackets[index], regexFilter ? regex : sharedVars.lastFilter, sharedVars.hiddenPackets, inverseFiltering, - regexFilter)) { + regexFilter, + sharedVars)) { // If it's hidden, show it array[index] = [item[0].replace('filter-hidden', 'filter-shown')] } else { diff --git a/html/mainPage/js/packetDom.js b/html/mainPage/js/packetDom.js index e38cc97..8ba24b5 100644 --- a/html/mainPage/js/packetDom.js +++ b/html/mainPage/js/packetDom.js @@ -39,7 +39,8 @@ function formatTime (ms) { exports.addPacketToDOM = function (packet) { const isHidden = filteringLogic.packetFilteredByFilterBox(packet, sharedVars.lastFilter, sharedVars.hiddenPackets, // TODO: cache these? - sharedVars.settings.getSetting('inverseFiltering'), sharedVars.settings.getSetting('regexFilter')) + sharedVars.settings.getSetting('inverseFiltering'), sharedVars.settings.getSetting('regexFilter'), + sharedVars) sharedVars.allPacketsHTML.push([ `