From f24cfc32734a168254f0c0e4889a989bb69ee444 Mon Sep 17 00:00:00 2001
From: sowgro <tpoke.ferrari@gmail.com>
Date: Tue, 15 Oct 2024 23:20:33 -0400
Subject: populate widgets with actual bookmarks

---
 extension/src/main.tsx | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 extension/src/main.tsx

(limited to 'extension/src/main.tsx')

diff --git a/extension/src/main.tsx b/extension/src/main.tsx
new file mode 100644
index 0000000..36df6f6
--- /dev/null
+++ b/extension/src/main.tsx
@@ -0,0 +1,45 @@
+import { createRoot } from 'react-dom/client'
+import './index.css'
+import Folder from "./Folder.tsx";
+import BookmarkTreeNode = chrome.bookmarks.BookmarkTreeNode;
+import Bookmark from "./Bookmark.tsx";
+
+chrome.bookmarks.getTree((tree) => {
+    createRoot(document.getElementById('root')!).render(createFolder(tree[0]))
+});
+
+function createFolder(lev: BookmarkTreeNode) {
+    return (
+        <Folder name={lev.title}>
+            {
+                lev.children ? lev.children.map(item => {
+                    if (item.children) {
+                        return createFolder(item)
+                    } else {
+                        return <Bookmark name={item.title} url={item.url ? item.url : ""} icon={faviconURL(item.url)} />
+                    }
+                }) : <span>err</span>
+            }
+        </Folder>
+    )
+}
+
+function faviconURL(u: string | undefined) {
+    if (!u) {
+        return "";
+    }
+    u = new URL(u).origin.toString();
+    const url = new URL(chrome.runtime.getURL("/_favicon/"));
+    url.searchParams.set("pageUrl", u);
+    url.searchParams.set("size", "32");
+    console.log(u)
+    return url.toString();
+}
+
+
+// chrome.bookmarks.create(
+//     {'parentId': '0', 'title': 'Bookmarks Extension'},
+//     function (newFolder) {
+//         console.log("added folder: " + newFolder.title);
+//     },
+// );
\ No newline at end of file
-- 
cgit v1.2.3

