/* Rule no. 1 in ES6 is to first add the modules. */ import {modifyDatabaseEntry, syncWithServer, setHighlightedText} from "../auto_store.js"; /* Get categories array from storage DB */ var categories = browser.storage.local.get("category").then((categoryArray) => {getCategories(categoryArray["category"]);}); /* Add event listeners to some buttons*/ const textareaListener = document.getElementById("atn"); textareaListener.addEventListener("click", checkAnnotationText, false); const closeListener = document.getElementById("ctn"); closeListener.addEventListener("click", function(){window.close()}, false); /* Display any highlighted text */ /* Generic error handler */ function onError(error){ console.log(error) } /* Get promised categories and display them as checkboxes */ function getCategories(item){ if(item != undefined){ var categories = item; } /* Loop through all category objects and create HTML radio buttons for them*/ var text, fLen, i; fLen = categories.length; text = "
"; // Display loop of categories document.getElementById("main").innerHTML = text; // Event listeners const checkboxListener = document.getElementById("btn"); checkboxListener.addEventListener("click", checkCheckboxValues, false); // Display the annotations box //displayHighlightedText(); // Return stuff return categories; } // Fetch checkbox values function checkCheckboxValues(){ let rbs = document.querySelectorAll('input[name="category"]:checked'); let selectedCategories = []; for(var i=0; i < rbs.length; i++){ console.log("Checked is: ", rbs[i].value); selectedCategories.push(rbs[i].value); } console.log("Checkbox's selected values: ", selectedCategories); //saveSelectedTextToCategory(selectedValues); modifyDatabaseEntry("category", selectedCategories); //window.close(); } function checkAnnotationText(){ var annotation = document.getElementById("annotation").value; console.log("Received annotation text: ", annotation); /* Save to DB */ modifyDatabaseEntry("annotation", annotation); } /* Display the selected text in the HTML popup. function displayHighlightedText(){ var highlightedText = setHighlightedText("get"); var markedField = "