diff --git a/gtav-interactive-map/index.html b/gtav-interactive-map/index.html index 66f39b1..9a7cb0b 100644 --- a/gtav-interactive-map/index.html +++ b/gtav-interactive-map/index.html @@ -43,6 +43,7 @@ + diff --git a/gtav-interactive-map/menus/settings/data.js b/gtav-interactive-map/menus/settings/data.js new file mode 100644 index 0000000..a29e128 --- /dev/null +++ b/gtav-interactive-map/menus/settings/data.js @@ -0,0 +1,46 @@ +function dataSettings() { + resetContentPart2(); + let optionDiv = document.createElement("div"); + optionDiv.innerHTML = "Backup Data
Click Here
"; + + optionDiv.addEventListener("click", function () { + saveDataSave(); + var element = document.createElement("a"); + element.setAttribute( + "href", + "data:text/plain;charset=utf-8," + + encodeURIComponent(localStorage.getItem("saveData")) + ); + element.setAttribute("download", "GTA5InteractiveMapData.json"); + element.style.display = "none"; + document.body.appendChild(element); + element.click(); + document.body.removeChild(element); + }); + + contentPart2.append(optionDiv); + + let option2Div = document.createElement("div"); + option2Div.innerHTML = "Load Backup DataClick Here
"; + + option2Div.addEventListener("click", function () { + var element = document.createElement("input"); + element.type = "File"; + element.accept = "application/json, text/plain"; + element.addEventListener("change", function (e) { + let reader = new FileReader(); + reader.addEventListener("load", function (res) { + console.log(res.target.result); + loadInSaveData(res.target.result); + saveDataSave(); + window.location.reload(); + }); + reader.readAsText(e.target.files[0]); + }); + document.body.appendChild(element); + element.click(); + document.body.removeChild(element); + }); + + contentPart2.append(option2Div); +} diff --git a/gtav-interactive-map/script.js b/gtav-interactive-map/script.js index a9cfbb1..e2a8c0b 100644 --- a/gtav-interactive-map/script.js +++ b/gtav-interactive-map/script.js @@ -291,57 +291,10 @@ Array.from(document.getElementById("menuScroll").children).forEach((r) => ); /* Data Options */ - let dataButton = addToContentPart1List("Data"); - - dataButton.addEventListener("click", function () { - resetContentPart2(); - let optionDiv = document.createElement("div"); - optionDiv.innerHTML = "Backup DataClick Here
"; - - optionDiv.addEventListener("click", function () { - saveDataSave(); - var element = document.createElement("a"); - element.setAttribute( - "href", - "data:text/plain;charset=utf-8," + - encodeURIComponent(localStorage.getItem("saveData")) - ); - element.setAttribute( - "download", - "GTA5InteractiveMapData.json" - ); - element.style.display = "none"; - document.body.appendChild(element); - element.click(); - document.body.removeChild(element); - }); - - contentPart2.append(optionDiv); - - let option2Div = document.createElement("div"); - option2Div.innerHTML = "Load Backup DataClick Here
"; - - option2Div.addEventListener("click", function () { - var element = document.createElement("input"); - element.type = "File"; - element.accept = "application/json, text/plain"; - element.addEventListener("change", function (e) { - let reader = new FileReader(); - reader.addEventListener("load", function (res) { - console.log(res.target.result); - loadInSaveData(res.target.result); - saveDataSave(); - window.location.reload(); - }); - reader.readAsText(e.target.files[0]); - }); - document.body.appendChild(element); - element.click(); - document.body.removeChild(element); - }); - - contentPart2.append(option2Div); - }); + addToContentPart1List("Data").addEventListener( + "click", + dataSettings + ); contentPart1.children[0].click(); return;