Please improve the code below. Thank you. function processcurrentNode(currentNode,…
- User
Please improve the code below. Thank you. function processcurrentNode(currentNode, targetUrl, ancestorList) { const ROOT_FOLDER_ID = "1"; if (currentNode.url === targetUrl) { chrome.bookmarks.move(currentNode.id, { index: 0 }); var matchedBookmark = currentNode; if ( matchedBookmark.parentId != ROOT_FOLDER_ID) { for (var index = 1; index < ancestorList.length; ++index) { if (ancestorList[index].id != 1) chrome.bookmarks.move(ancestorList[index].id, { index: 0 }); } } }
codeif (currentNode.children && currentNode.children.length > 0) { ancestorList.push(currentNode); traverseBookmarkTree(currentNode.children, targetUrl, ancestorList); ancestorList.pop(); }}
function traverseBookmarkTree(currentNodes, targetUrl, ancestorList) { for (var i = 0; i < currentNodes.length; i++) { processcurrentNode(currentNodes[i], targetUrl, ancestorList); } }
chrome.history.onVisited.addListener(function (historyItem) { chrome.bookmarks.getTree(function (bookmarkTreeNodes) { var ancestorList = []; traverseBookmarkTree(bookmarkTreeNodes, historyItem.url, ancestorList); }); });
chrome.webRequest.onBeforeRequest.addListener(function(details) { // console.info("URL :" + details.url); chrome.bookmarks.getTree(function (bookmarkTreeNodes) { var webRequestAncestorList = []; traverseBookmarkTree(bookmarkTreeNodes, details.url, webRequestAncestorList); }); }, {urls: ["<all_urls>"]} );
- Assistant