Google chrome extension 在chrome扩展中筛选特定书签文件夹项目
我需要获得一个特定的书签组或文件夹“代码库”中的许多根文件夹存在。此外,我需要在弹出的html表单中显示“代码库”下的子文件夹或子组。从chrome文档中,我相信下面的函数可以做这些事情,但它需要文件夹的ID,如何获取IDGoogle chrome extension 在chrome扩展中筛选特定书签文件夹项目,google-chrome-extension,Google Chrome Extension,我需要获得一个特定的书签组或文件夹“代码库”中的许多根文件夹存在。此外,我需要在弹出的html表单中显示“代码库”下的子文件夹或子组。从chrome文档中,我相信下面的函数可以做这些事情,但它需要文件夹的ID,如何获取ID chrome.bookmarks.getSubTree(string id, function callback) 仅供参考,弹出式html表单由脚本外部控制,我需要在脚本中放置上述要求的代码。 谢谢你的时间 我使用了下面的代码来解决问题,请任何人通过检查此答案的“正确”符
chrome.bookmarks.getSubTree(string id, function callback)
仅供参考,弹出式html表单由脚本外部控制,我需要在脚本中放置上述要求的代码。
谢谢你的时间 我使用了下面的代码来解决问题,请任何人通过检查此答案的“正确”符号或通过注释来验证下面的代码
var temP = [];
var found;
$(document).ready(function(){
chrome.bookmarks.getTree(function(bookmarks){
found = search_for_title(bookmarks, "here goes title of an existing bookmark which user need to search"); // found variable will have the id of bookmark we r searching.
chrome.bookmarks.getChildren(found, function(children) { //using the ID of the bookmark we can process further requirement
children.forEach(function(bookmark) { // here i'm dwelling into sub folder to extract the content
console.debug(bookmark.title);// these were the subfolder titles
console.log(bookmark.id);// these were the subfolder ids
});
});
});
function search_for_title(bookmarks, title){ // first argument is entire bookmarks, second argument is title which we specified for search
for(var i=0; i < bookmarks.length; i++){
if(bookmarks[i].title == title){
return bookmarks[i].id; // we will get the id of the bookmark we are searching for
}
else{
if(bookmarks[i].children){
var id = search_for_title(bookmarks[i].children, title);
if(id)
return id;
}
}
}
return false;
}
});
var-temP=[];
var发现;
$(文档).ready(函数(){
chrome.bookmarks.getTree(函数(书签){
found=search_for_title(bookmarks,“用户需要搜索的现有书签的标题”);//found变量将具有我们正在搜索的书签的id。
chrome.bookmarks.getChildren(find,function(children){//使用书签的ID,我们可以处理进一步的需求
forEach(function(bookmark){//这里我将驻留在子文件夹中以提取内容
console.debug(bookmark.title);//这些是子文件夹标题
console.log(bookmark.id);//这些是子文件夹id
});
});
});
函数search_for_title(bookmarks,title){//第一个参数是完整的bookmarks,第二个参数是我们为搜索指定的title
对于(var i=0;i
谢谢