From 097ea455f8c78c3a622e0f81b351cb524d11be14 Mon Sep 17 00:00:00 2001 From: CennoxX <6975881+CennoxX@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:11:36 +0100 Subject: [PATCH] fix search with date, display message if nothing matches --- extension/js/preferences.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/extension/js/preferences.js b/extension/js/preferences.js index d53b91f..2275ae7 100644 --- a/extension/js/preferences.js +++ b/extension/js/preferences.js @@ -121,7 +121,7 @@ } chrome.storage.local.get(function(results) { var allPages = [] - var queryParts = query.match(/(?:[^\s"]+|"[^"]*")+/g).map(i => i.replace(/"/g, '')); + var queryParts = query.match(/(?:[^\s"]+|"[^"]*")+/g)?.map(i => i.replace(/"/g, '')); for (key in results) { if (!isNaN(key) && (results[key].url + '/' + results[key].title + '/' + results[key].text).indexOf(query) != -1) { allPages.push(results[key]) @@ -129,6 +129,17 @@ allPages.push(results[key]) } } + if (allPages.length == 0){ + while (history_table.hasChildNodes()) { + history_table.removeChild(history_table.lastChild); + } + var emptyRow = document.createElement('tr'); + var emptyColumn = document.createElement('td'); + emptyColumn.setAttribute('class','center aligned'); + emptyColumn.textContent = 'No entry found'; + emptyRow.appendChild(emptyColumn); + history_table.appendChild(emptyRow); + } allPages.reverse() allPageDisplay = nextPages(allPages) addHistoricPages(allPageDisplay.next().value) @@ -233,7 +244,7 @@ } document.addEventListener('DOMContentLoaded', function(event){ - var query = unescape(location.search?.substring(7).replace(/(before|after): ?(\w+|"[^"]+") ?/g,'')); + var query = unescape(location.search?.substring(7).replace(/(before|after): ?([^" ]+|"[^"]+") ?/g,'')); document.getElementById('search_history').value = query; getHistory(query);