Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

saveLocal.js 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var storage = window.localStorage;
  2. function loadFile(filePath) {
  3. var result = null;
  4. var xmlhttp = new XMLHttpRequest();
  5. xmlhttp.open("GET", filePath, false);
  6. xmlhttp.send();
  7. if (xmlhttp.status==200) {
  8. result = xmlhttp.responseText;
  9. }
  10. return result;
  11. }
  12. function checkDate() {
  13. var date = loadFile("https://artesaniaspr.online/date.txt");
  14. if (window.localStorage.getItem("DATE") == null || window.localStorage.getItem("DATE") != date) {
  15. window.localStorage.setItem("DATE", date);
  16. return false;
  17. }
  18. else {
  19. return true;
  20. }
  21. }
  22. try {
  23. if (checkDate() == false) {
  24. window.localStorage.setItem("RENGLONES", loadFile("https://artesaniaspr.online/renglones.json"));
  25. var renglones = JSON.parse(window.localStorage.getItem("RENGLONES"));
  26. for (var i = 0; i < renglones.length; i++) {
  27. window.localStorage.setItem(renglones[i].Renglones, loadFile("https://artesaniaspr.online/" + renglones[i].Renglones + ".json"));
  28. }
  29. }
  30. } catch {
  31. console.log("error");
  32. }