From 326adeb5acdda68bf726e8997d565c91d3797282 Mon Sep 17 00:00:00 2001 From: abhinandkr Date: Sun, 25 Sep 2022 19:28:33 +0530 Subject: [PATCH] Appending question set file name to the message * Shows the question set file name (if present) when the page is loaded * This helps the reader to know the exact set that is loaded if the page is refreshed/reopened. Issue link: https://github.com/harishkrishnav/FLQL-show-questions/issues/2 --- popup.js | 1 + showQuestions.js | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/popup.js b/popup.js index 95e2aca..1f82391 100644 --- a/popup.js +++ b/popup.js @@ -7,6 +7,7 @@ loadButton.addEventListener("click", async () => { fileReader.onload = async function (fileLoadedEvent) { var textFromFileLoaded = fileToArray(fileLoadedEvent.target.result); chrome.storage.local.set({ questions: textFromFileLoaded }); + chrome.storage.local.set({ fileName }); //console.log(textFromFileLoaded); let [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); chrome.scripting.executeScript({ diff --git a/showQuestions.js b/showQuestions.js index d55fca9..7fd6a30 100644 --- a/showQuestions.js +++ b/showQuestions.js @@ -19,22 +19,27 @@ var converter = new showdown.Converter(); async function showInstructions() { var elements = document.getElementsByTagName("div"); var noteText = "Upload the questions before you hit start"; - chrome.storage.local.get("questions", ({questions}) => { - if (questions && questions.length>2) { - noteText = "There is already a loaded set of questions in the browser cache. Re-upload if you want to be sure, and click start." - } - for (item of elements) { - try { - if (item.className === "cell w99 h10") { - item.id = "42"; - const instructionsElement = getInstructionsElement(noteText); - item.append(instructionsElement); - } - } catch (e) {} + const {questions} = await chrome.storage.local.get("questions"); + if (questions && questions.length > 2) { + const {fileName} = await chrome.storage.local.get("fileName"); + noteText = "There is already a loaded set of questions in the browser cache. "; + if (fileName !== "") { + noteText += `Question set name: "${fileName}". `; } - }); + noteText += "Re-upload if you want to be sure, and click start."; + } + for (item of elements) { + try { + if (item.className === "cell w99 h10") { + item.id = "42"; + const instructionsElement = getInstructionsElement(noteText); + item.append(instructionsElement); + } + } catch (e) {} + } } + /* ----------------------------------------- */ //showQuestion must be called each time a button is clicked async function updateButtons() {