是否可以增加chrome.bookmarks.MAX_WRITE_OPERATIONS_PER_HOUR?

时间:2013-03-25 07:36:33

标签: google-chrome-extension

我尝试将属性设置为更高的值但它似乎不起作用。知道我应该怎么做吗? (这是一个扩展,允许您在多个书签栏之间切换。)

文档在这里:https://developer.chrome.com/extensions/bookmarks.html

编辑:下面是源代码。

(function(){
    function f(d) {
        chrome.bookmarks.MAX_WRITE_OPERATIONS_PER_HOUR = 100000000;
        chrome.bookmarks.MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE = 2000000;
        chrome.bookmarks.getTree(function(tree) {
            if (!searchFolder(tree[0], "Switchmark")) {
                chrome.bookmarks.create({"title": "Switchmark"}, function(n){
                    chrome.bookmarks.create({"title": "A", parentId: n.id});
                    chrome.bookmarks.create({"title": "B", parentId: n.id});
                    chrome.browserAction.setBadgeText({"text": "A"});
                });
            } else {
                for (var i = 0; i < children.length; i++) {
                    if (!children[i].children.length) {
                        chrome.browserAction.setBadgeText({"text": children[i].title});
                        break;
                    }
                }
            }
        });
    }
    chrome.runtime.onInstalled.addListener(f);
    chrome.runtime.onStartup.addListener(f);
}).call();

chrome.browserAction.onClicked.addListener(function(t) {
    chrome.bookmarks.getTree(function(tree) {
        var children = searchFolder(tree[0], "Switchmark").children;
        for (var i = 0; i < children.length; i++) {
            if (!children[i].children.length) {
                var barId = searchFolder(tree[0], "Bookmarks bar").id;
                var currentId = children[i].id;
                var nextNode = children[++i < children.length ? i : 0];
                var nextId = nextNode.id;
                var nextTitle = nextNode.title;
                moveFolderContents(barId, currentId);
                moveFolderContents(nextId, barId);
                chrome.browserAction.setBadgeText({"text": nextTitle});
                break;
            }
        }
    });
});

function moveFolderContents(fromId, toId) {
    chrome.bookmarks.getSubTree(fromId, function (subtree) {
        var c = subtree[0].children;
        for (var i = 0; i < c.length; i++) chrome.bookmarks.move(c[i].id, {"parentId": toId});
    });
}

function searchFolder(n, f) {
    if (Array.isArray(n.children)) {
        for (var i = 0; i < n.children.length; i++) {
            if (n.children[i].title == f) return n.children[i];
            else if (r = searchFolder(n.children[i], f)) return r;
        }
    }
    return null;
}

0 个答案:

没有答案