Added loading of bookmark links from localStorage

This commit is contained in:
Tionis Nagir 2020-05-14 14:52:48 +02:00
parent 531524d192
commit 9880643655

View file

@ -1,15 +1,24 @@
var data_links = "links.json"; 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 () { document.addEventListener("DOMContentLoaded", function () {
fetch(data_links) if (!bookmarks) {
.then( response => response.json()) fetch(data_links)
.then( .then(response => response.json())
function (data) { .then(function (data) {
var mysource = document.getElementById("links-template").innerHTML; handleLinks(data);
var mytemplate = Handlebars.compile(mysource); localStorage.setItem("links", JSON.stringify(data));
var myresult = mytemplate(data) });
document.getElementById("links").innerHTML = myresult; } else {
}); handleLinks(bookmarks);
}
}); });
var data_apps = "apps.json"; var data_apps = "apps.json";