diff --git a/assets/js/data.js b/assets/js/data.js index 14f0413..cf8b9c9 100755 --- a/assets/js/data.js +++ b/assets/js/data.js @@ -1,15 +1,24 @@ var data_links = "links.json"; +var bookmarks = JSON.parse(localStorage.getItem("links")); + +function handleLinks(data) { + var mysource = document.getElementById("links-template").innerHTML; + var mytemplate = Handlebars.compile(mysource); + var myresult = mytemplate(data) + document.getElementById("links").innerHTML = myresult; +} document.addEventListener("DOMContentLoaded", function () { - fetch(data_links) - .then( response => response.json()) - .then( - function (data) { - var mysource = document.getElementById("links-template").innerHTML; - var mytemplate = Handlebars.compile(mysource); - var myresult = mytemplate(data) - document.getElementById("links").innerHTML = myresult; - }); + if (!bookmarks) { + fetch(data_links) + .then(response => response.json()) + .then(function (data) { + handleLinks(data); + localStorage.setItem("links", JSON.stringify(data)); + }); + } else { + handleLinks(bookmarks); + } }); var data_apps = "apps.json";