12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- localStorage.setItem("RENGLONES", loadFile("https://artesaniaspr.website/renglones2.json"));
- localStorage.setItem("AZAR", loadFile("https://artesaniaspr.website/azar.json"));
- let renglones = JSON.parse(window.localStorage.getItem("RENGLONES"));
-
- //A synchronous request to the server
- function loadFile(filePath) {
- var result = null;
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.open("GET", filePath, false);
- xmlhttp.send();
- if (xmlhttp.status==200) {
- result = xmlhttp.responseText;
- }
- return result;
- }
-
-
- //Checks if date has changed in the server or if number or renglones has been shortened (since local storage can be erased when the device runs out of memory)
- function checkDate() {
- var date = loadFile("https://artesaniaspr.website/date.txt");
- if (localStorage.getItem("DATE") == null || localStorage.getItem("DATE") != date || localStorage.length < 17) {
- localStorage.setItem("DATE", date);
- return false;
- }
- else {
- return true;
- }
- }
-
-
- try {
- if (checkDate() == false) {
-
- window.localStorage.setItem("TODOS", loadFile("https://artesaniaspr.website/artesanias2.json"));
-
- //For each name it finds in renglones, it requests the json in the server and saves them in local storage
- for (var i = 0; i < renglones.length; i++) {
- localStorage.setItem(renglones[i].Renglones, loadFile("https://artesaniaspr.website/" + renglones[i].Renglones + ".json"));
- }
- }
- } catch {
- console.log("error");
- }
|