在Chrome扩展程序中过滤特定的书签文件夹项目 [英] Filtering a specific bookmark folder item in chrome extension

查看:94
本文介绍了在Chrome扩展程序中过滤特定的书签文件夹项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取当前存在的许多根文件夹中的特定书签组或文件夹代码库".另外,我需要在代码库"下将其子文件夹或子组显示到我的Popup html表单中.从chrome文档,我相信下面的功能可以完成这些工作,但是它需要文件夹的ID,如何获取ID?

I need to obtain a specific bookmark group or folder "codebase" among many root folders present. Also, i need to display its sub folder or sub group under "codebase" into my Popup html form. From chrome docs, i believe below function can do the stuff, but it needs ID of the folder, how to obtain the ID ?

chrome.bookmarks.getSubTree(string id, function callback)

仅供参考,弹出html表单由脚本外部控制,我需要在上面放置满足上述要求的代码. 感谢您的宝贵时间!!!

FYI, popup html form is externally controlled by a script, where i need to place the code for above requirement. Thanks for your time !!!

推荐答案

我使用下面的代码解决了这个问题,请问任何人都可以通过检查此答案的正确"符号或注释来证明下面的代码.

I used the below code to solve the problem, Could anyone please certify the below code by checking the "correct" symbol for this answer or by comment.

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;
    }
});

谢谢

这篇关于在Chrome扩展程序中过滤特定的书签文件夹项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆