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 bookmarks = JSON.parse(localStorage.getItem("links"));
document.addEventListener("DOMContentLoaded", function () {
fetch(data_links)
.then( response => response.json())
.then(
function (data) {
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 () {
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";