[关闭]
@zoand 2015-07-01T22:41:31.000000Z 字数 1087 阅读 1544

chrome书签的增删改查

chrome插件


1. 先请求权限:

  1. "permissions": [
  2. "bookmarks"
  3. ]

2. 创建书签:

  1. chrome.bookmarks.create({
  2. parentId: '1',
  3. index: 0,
  4. title: 'Google',
  5. url: 'http://www.google.com/'
  6. }, function(bookmark){
  7. console.log(bookmark);
  8. });

3. 移动书签:

  1. chrome.bookmarks.move('16', {
  2. parentId:'7',
  3. index:4
  4. }, function(bookmark){
  5. console.log(bookmark);
  6. });

4. 删除书签:

  1. chrome.bookmarks.remove('16', function(){
  2. console.log('Bookmark 16 has been removed.');
  3. });
  4. chrome.bookmarks.removeTree('6', function(){
  5. console.log('Bookmark group 6 has been removed.');
  6. });

5. 获取整个书签:

  1. chrome.bookmarks.getTree(function(bookmarkArray){
  2. console.log(bookmarkArray);
  3. });

6. 获取根节点的所有子节点:

  1. chrome.bookmarks.getChildren('0', function(bookmarkArray){
  2. console.log(bookmarkArray);
  3. });

7. 获取指定节点及下面所有子孙节点:

  1. chrome.bookmarks.getSubTree('0', function(bookmarkArray){
  2. console.log(bookmarkArray);
  3. });

8. 获取指定节点对象(id为16和17的书签对象):

  1. chrome.bookmarks.get(['16', '17'], function(bookmarkArray){
  2. console.log(bookmarkArray);
  3. });

9. 取最新添加的书签(5条记录):

  1. chrome.bookmarks.getRecent(5, function(bookmarkArray){
  2. console.log(bookmarkArray);
  3. });

10. 条件匹配搜索书签对象

  1. chrome.bookmarks.search('google', function(bookmarkArray){
  2. console.log(bookmarkArray);
  3. });
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注