Skip to content

Instantly share code, notes, and snippets.

@alejandrocoding
Created June 24, 2020 12:50
Show Gist options
  • Save alejandrocoding/7769b7566dc74109ee90d48856513b14 to your computer and use it in GitHub Desktop.
Save alejandrocoding/7769b7566dc74109ee90d48856513b14 to your computer and use it in GitHub Desktop.
Calling addBookMarkFolder & addBookMarkLink from onMessage Listener
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.myBookMark) {
chrome.bookmarks.getTree((bookmarks) => { // let's search and try to find if the folder already exists
const bookmarkBar = bookmarks[0].children.find(bookmark => bookmark.id === '1'); // the bookmar bar is given id '1'
const existAlready = bookmarkBar.children.find(bookmark => bookmark.title === BOOKMARK_FOLDER.title);
if (!existAlready) {
addBookMarkFolder()
.pipe(concatMap((folder) => addBookMarkLink(folder))) // concat to pass the folder created value down to addBookMarkLink
.subscribe((result) => sendResponse(result)); // sending as a response the result
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment