if (!localStorage.getItem("SessionID")) { window.location.href = "/login.html"; } window.addEventListener("load", async () => { console.log("loading..."); const rootFolder = await getFolder(); const bm = document.getElementById("bookmarks"); if (!rootFolder.success) { bm.textContent = "Нет закладок"; return; } if (!bookmark || !folder) { return; } for (let f of rootFolder.folder.ChildFolders) { const clone = createFolderElement(f); bm.appendChild(clone); } for (let b of rootFolder.folder.ChildBookmarks) { const clone = createBookmarkElement(b); bm.appendChild(clone); } feather.replace(); }); function createFolderElement(folder) { const template = document.querySelector("#folder"); const clone = template.content.firstElementChild.cloneNode(true); clone.querySelector("#folder_name").textContent = folder.Name; clone.addEventListener("click", () => { alert(folder.Name); }); for (let el of clone.querySelectorAll("[data-feather-t]")) { el.setAttribute("data-feather", el.getAttribute("data-feather-t")); } clone.querySelector(".xmark").addEventListener("click", (e) => { alert(`${folder.Name} was deleted`); e.stopPropagation(); }); return clone; } function createBookmarkElement(bookmark) { const template = document.querySelector("#bookmark"); const tagtempl = document.querySelector("#booktag"); const clone = template.content.firstElementChild.cloneNode(true); clone.querySelector("#bookmark_name").textContent = bookmark.Name; const link = clone.querySelector("#bookmark_link"); link.setAttribute("href", bookmark.Url); link.textContent = bookmark.Url; for (let tag of bookmark.Tags) { const t = tagtempl.content.cloneNode(true); const el = t.querySelector("span"); el.addEventListener("onclick", () => alert(tag)); el.textContent = "#" + tag; clone.querySelector("#bookmark_tags").appendChild(t); } for (let el of clone.querySelectorAll("[data-feather-t]")) { el.setAttribute("data-feather", el.getAttribute("data-feather-t")); } clone.querySelector(".xmark").addEventListener("click", (e) => { alert(`${bookmark.Name} was deleted`); e.stopPropagation(); }); return clone; }