Skip to content

Commit

Permalink
fixed searching
Browse files Browse the repository at this point in the history
  • Loading branch information
hpat0003 committed Nov 8, 2018
1 parent f116621 commit 165cead
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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), []);
Expand All @@ -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()}))
Expand All @@ -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;
}
Expand Down
14 changes: 4 additions & 10 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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');
});
Expand Down

0 comments on commit 165cead

Please sign in to comment.