Откройте несколько вкладок в новом окне Chrome - PullRequest
0 голосов
/ 19 декабря 2018

Я хочу смоделировать пункт контекстного меню менеджера закладок Chrome любой папки закладок «Открыть все закладки в новом окне».Утром, когда я запускаю Windows 8.1 и Chrome, закладки из 4 папок должны появляться в 4 отдельных окнах Chrome.

Вот мои попытки открыть одно новое окно:

manifest.json

{
    "manifest_version": 2,
    "name": "MyChromeExtension",
    "description": "Description of my Chrome Extension.",
    "version": "1.0",
    "background": {
        "scripts": [ "atExtensionLoad.js" ],
        "persistent": false
    },
    "permissions": [ "tabs", "bookmarks" ],
    "icons": {
        "16": "images/get_started16.png",
        "32": "images/get_started32.png",
        "48": "images/get_started48.png",
        "128": "images/get_started128.png"
    }
}

atExtensionLoad.js

'use strict';

chrome.runtime.onInstalled.addListener(function () {

    // Search the bookmarks for the folder with the name "Spotify"
    chrome.bookmarks.search("Spotify", function (bookmarkTreeNodes) {
        if (bookmarkTreeNodes.length > 0) {
            // Open all bookmarks of the folder
            openNewWindow(bookmarkTreeNodes[0]);
        }
    });

    // Should open all bookmarks of the given folder inside a new Chrome window
    function openNewWindow(bookmarkTreeNode) {
        // Get all bookmarks of the folder ...
        chrome.bookmarks.getChildren(bookmarkTreeNode.id, function (tabs) {
            // ... and open them as additional tabs inside the existing window
            for (var i = 0; i < tabs.length; i++) {
                // A
                chrome.tabs.create({
                    url: tabs[i].url
                });
                // B (has the same effect as A)
                //window.open(tabs[i].url);
            }
        });

        // One possibility: How can I push the opened tabs into a new Chrome window?
    };
});

1 Ответ

0 голосов
/ 19 декабря 2018

Что-то вроде:

chrome.bookmarks.getChildren(bookmarkTreeNode.id, function (tabs) {
    //create a new window with all the bookmarks, each on one tab
    chrome.windows.create({url: tabs.map(tab=>tab.url)});
});
...