Created
June 24, 2020 12:50
-
-
Save alejandrocoding/7769b7566dc74109ee90d48856513b14 to your computer and use it in GitHub Desktop.
Calling addBookMarkFolder & addBookMarkLink from onMessage Listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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