diff --git a/HKCheckCompletion.js b/HKCheckCompletion.js index b5dc375..0e17f51 100644 --- a/HKCheckCompletion.js +++ b/HKCheckCompletion.js @@ -203,9 +203,7 @@ function HKCheckCompletion(jsonObject) { let countBegin = new Date(); // Pre-Cleaning all divs for safety - for (i in DIV_ID) { - document.getElementById(DIV_ID[i]).innerHTML = ""; - } + cleanHTML(DIV_ID); // Shallow Clone const objects (used for destructive functions) let HK_BOSSES_temp = Object.assign({}, HK_BOSSES); @@ -328,6 +326,12 @@ function HKCheckCompletion(jsonObject) { console.info("HKCheckCompletion() time (ms) =", countEnd - countBegin); } +function cleanHTML(jsObj) { + for (i in jsObj) { + document.getElementById(jsObj[i]).innerHTML = ""; + } +} + function fillHTML(divId = "", textPrefix = "Unknown Completion Element: ", textSuffix = "") { document.getElementById(divId).innerHTML += divStart + completionSymbol + strongStart + textPrefix + "" + strongEnd + currentData + textSuffix + divEnd; } diff --git a/loadJson.js b/loadJson.js index 1b3e2c1..a70d967 100644 --- a/loadJson.js +++ b/loadJson.js @@ -1,10 +1,11 @@ -var jsonObj; +var jsonObj = ""; /** * Reads the .json file and parses it to a JS object (jsonObj). * @param callback Asynchronous function. */ function loadJSON(callback) { + jsonObj = ""; // new Http request object (asynchronous), both the web page and the XML file it tries to load, must be located on the same server. var xobj = new XMLHttpRequest(); @@ -41,19 +42,16 @@ loadJSON( ); function HKReadTextArea() { + jsonObj = ""; + + cleanHTML(DIV_ID); + let textAreaId = "save-area"; let contents = document.getElementById(textAreaId).value; if(contents.length > 0) { - jsonObj = contents; - - loadJSON( - function JSONparse(response) { - // Parse JSON string into object - jsonObj = JSON.parse(response); - HKCheckCompletion(jsonObj); - // console.log(jsonObj); - } - ); + jsonObj = JSON.parse(contents); + HKCheckCompletion(jsonObj); + // console.log(jsonObj); } } \ No newline at end of file