From 165ceada449aefd000b4b6a353b6f721a02a8aed Mon Sep 17 00:00:00 2001 From: hpat0003 Date: Fri, 9 Nov 2018 03:40:01 +1100 Subject: [PATCH] fixed searching --- src/background.js | 10 +++++----- src/popup.js | 14 ++++---------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/background.js b/src/background.js index 3898d41..622ae27 100755 --- a/src/background.js +++ b/src/background.js @@ -11,7 +11,7 @@ function getFilesUnderSection() { .filter(resource => ( // filtering out just the files. Noob filtering going on here 😝 resource.getElementsByClassName("instancename")[0].innerText.slice(-4) == "File")) .map(resource => ({ - name: resource.getElementsByClassName("instancename")[0].innerText.slice(0, -4).trim(), + name: resource.getElementsByClassName("instancename")[0].innerText.slice(0, -4).trim().toLowerCase(), url: resource.getElementsByTagName("a")[0].href + "&redirect=1", section: content.getElementsByTagName("h3")[0].innerText.trim()}))) .reduce((x, y) => x.concat(y), []); @@ -22,7 +22,7 @@ function getFilesUnderResources() { .filter(resource => resource.getElementsByTagName('img').length != 0) // .filter(resource => resource.getElementsByTagName('img')[0]['alt'] == "File") .map(resource => (resource = { - name: resource.getElementsByTagName('a')[0].innerText.trim(), + name: resource.getElementsByTagName('a')[0].innerText.trim().toLowerCase(), url: resource.getElementsByTagName('a')[0].href + "&redirect=1", type: resource.getElementsByTagName('img')[0]['alt'], section: resource.getElementsByTagName('td')[0].innerText.trim()})) @@ -37,9 +37,9 @@ function getFiles() { let filesUnderSection = getFilesUnderSection() let filesUnderResources = getFilesUnderResources(); let allFiles = filesUnderSection.concat(filesUnderResources); - console.log(filesUnderSection); - console.log(filesUnderResources); - console.log(allFiles); + // console.log(filesUnderSection); + // console.log(filesUnderResources); + // console.log(allFiles); allFiles.forEach(file => file.course = courseName) return allFiles; } diff --git a/src/popup.js b/src/popup.js index 2e8ae53..53ef2b7 100755 --- a/src/popup.js +++ b/src/popup.js @@ -15,9 +15,6 @@ function main() { ga('set', 'checkProtocolTask', null); ga('send', 'pageview'); - // array of titles of resources in lower case - let resourceTitle = [] - // downloadResources on button press let button = document.getElementById("downloadResources"); button.addEventListener("click", () => { @@ -27,7 +24,7 @@ function main() { // filter resources on input let searchField = document.getElementById("search"); searchField.addEventListener("input", () => { - filterOptions(resourceTitle) + filterOptions() }); // executing background.js to populate the select form @@ -40,9 +37,6 @@ function main() { resources.forEach(resource => { let resourceOption = document.createElement("option"); - // saving titles in lower case - resourceTitle.push(resource.name.toLowerCase()) - // creating option element such that the text will be // the resource name and the option value its url. resourceOption.value = resource.url; @@ -110,13 +104,13 @@ function requestFeedback() { }); } -function filterOptions(resourceTitle) { +function filterOptions() { let searchField = document.getElementById("search"); let query = searchField.value.toLowerCase(); let options = document.getElementById("resourceSelector").options; - resourceTitle.forEach((title, index) => { - title.includes(query) ? + resourcesList.forEach((resource, index) => { + resource.name.includes(query) ? options[index].removeAttribute('hidden') : options[index].setAttribute('hidden', 'hidden'); });