From 9fcb20056fc6a5f8a7e3541cc75100e65c369c45 Mon Sep 17 00:00:00 2001 From: hpat0003 Date: Sat, 29 Sep 2018 09:27:45 +1000 Subject: [PATCH] =?UTF-8?q?added=20a=20search=20field=20=F0=9F=94=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- css/style.css | 7 +++---- popup.html | 17 ++++++++++++----- popup.js | 33 ++++++++++++++++++++++++--------- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8bffcd0..c0a506e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MoodleDownloader +# MoodleDownloader A chrome extension for downloading Moodle resources 💾 ## Download ⬇️ @@ -11,7 +11,7 @@ If you prefer to install manually, you can find the latest binaries [here](https 2. Open the week (section) from where you would like to download the resources from 3. Click on the extension icon and select the resources to be downloaded. - Click and drag or use ⌘ key to select multiple options: -4. Hit the `Download` button to get the resources! +4. Hit the `Download` button to get the resources! ## GIFs 🎞 ### Without MoodleDownloader 😩 @@ -28,7 +28,7 @@ If you prefer to install manually, you can find the latest binaries [here](https
#### Motivation 💡 -Realised in the week 11 that I don't have most of the resources 😭 +Realised in the week 11 that I don't have most of the resources 😭
diff --git a/css/style.css b/css/style.css index ed8e968..979f870 100644 --- a/css/style.css +++ b/css/style.css @@ -1,8 +1,7 @@ -#selectedResources { +#resourceSelector { font-size: 1rem; - height: 10rem; + height: 15rem; padding: .2rem .5rem; border: 1px solid rgba(0,0,0,.2); border-radius: .25rem; - } - + } \ No newline at end of file diff --git a/popup.html b/popup.html index 3c00a0a..f3e48f7 100755 --- a/popup.html +++ b/popup.html @@ -15,21 +15,28 @@ background: rgb(231, 242, 255); } --> - - + +

moodleDownloader 📚

-
+
+ Click and drag or use ⌘ key to select multiple options: - + +
+ +
- + \ No newline at end of file diff --git a/popup.js b/popup.js index 75edc65..2791476 100755 --- a/popup.js +++ b/popup.js @@ -1,6 +1,6 @@ function main() { - // google analytics + // google analytics var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-119398707-1']); _gaq.push(['_trackPageview']); @@ -15,32 +15,47 @@ function main() { let button = document.getElementById("downloadStuff"); button.addEventListener("click", () => downloadStuff()); + // filter resources on input + let searchField = document.getElementById("search"); + searchField.addEventListener("input", () => filterList()); + // executing background.js to populate the select form chrome.tabs.executeScript({file: "background.js"}, function(result) { try { - let selectedResources = document.getElementById("selectedResources"); + let resourceSelector = document.getElementById("resourceSelector"); let files = result[0]; files.forEach(file => { let fileOption = document.createElement("option"); + // creating option element such that the text will be // the resource name and the option value its url. fileOption.innerHTML = file.name; fileOption.value = file.url; - selectedResources.appendChild(fileOption); + resourceSelector.appendChild(fileOption); console.log('populated!'); }); } catch(error) { - console.log(error) + console.log(error); } }); } +function filterList() { + let searchField = document.getElementById("search"); + let query = searchField.value.toLowerCase(); + + let resourceSelector = document.getElementById("resourceSelector"); + Array.from(resourceSelector.options).forEach(option => { + option.innerHTML.toLowerCase().includes(query) ? + option.removeAttribute('hidden') : + option.setAttribute('hidden', 'hidden'); + }); + +} + function downloadStuff() { - console.log('button pressed!') - - let selectedResources = document.getElementById("selectedResources"); - Array.from(selectedResources.options).filter(x => x.selected).forEach(x => console.log(x, x.value)); - Array.from(selectedResources.options).filter(x => x.selected).forEach(x => chrome.downloads.download({url: x.value})); + let resourceSelector = document.getElementById("resourceSelector"); + Array.from(resourceSelector.options).filter(option => option.selected).forEach(option => chrome.downloads.download({url: option.value})); _gaq.push(['_trackEvent', 'downloadStuff', 'clicked']); }