v0.3: Extension #3

Merged
niklas merged 16 commits from develop into master 2020-04-25 20:38:57 +00:00
3 changed files with 61 additions and 1 deletions
Showing only changes of commit ed98f821bb - Show all commits

View File

@ -0,0 +1,43 @@
import { Bookmarks, Bookmark } from "../types/Bookmarks";
function createBookmark(from: browser.bookmarks.BookmarkTreeNode): Bookmark {
return {
name: from.title,
url: from.url
};
}
export default async (): Promise<Bookmarks> => {
const treeNode = await browser.bookmarks.getTree();
const root: Bookmarks = {
folder: [],
orphans: []
};
const rootNode = treeNode[0].children.find((e)=>e.id === "menu________");
// Set all top level bookmarks (without folder)
root.orphans = rootNode.children
.filter((e)=> e.type === "bookmark" )
.sort((a,b)=> a.index - b.index )
.map(createBookmark);
// Get all top level folders
root.folder = rootNode.children
.filter((e)=> e.type === "folder")
.filter((e)=> e.children.length > 0)
.sort((a,b)=> a.index - b.index )
.map((e)=>{
const children: Bookmark[] = e.children
.filter((e)=> e.type === "bookmark")
.sort((a,b)=> a.index - b.index )
.map(createBookmark);
return {
name: e.title,
bookmarks: children
};
});
return root;
};

View File

@ -13,7 +13,8 @@
"homepage": "startpage/index.html"
},
"permissions": [
"<all_urls>"
"<all_urls>",
"bookmarks"
],
"applications": {
"gecko": {

16
src/types/Bookmarks.ts Normal file
View File

@ -0,0 +1,16 @@
interface Bookmarks {
folder: BookmarkFolder[];
orphans: Bookmark[];
}
interface BookmarkFolder {
name: string;
bookmarks: Bookmark[];
}
interface Bookmark {
name: string;
url: string;
}
export { Bookmarks, Bookmark, BookmarkFolder };