diff --git a/api-samples/windows/README.md b/api-samples/windows/README.md new file mode 100644 index 00000000..a4a0d19c --- /dev/null +++ b/api-samples/windows/README.md @@ -0,0 +1,14 @@ +# chrome.windows + +This sample demonstrates using the `chrome.windows` and `chrome.tabs` API to manage tabs across different windows. + +## Overview + +The extension interates across all tabs and moves them to the currently active window. + +## Running this extension + +1. Clone this repository. +2. Load this directory in Chrome as an [unpacked extension](https://developer.chrome.com/docs/extensions/mv3/getstarted/development-basics/#load-unpacked). +3. Make sure you have multiple windows of chrome open. +4. Pin the extension and click on the action button. diff --git a/api-samples/windows/arrow_in.png b/api-samples/windows/arrow_in.png new file mode 100644 index 00000000..f0da7b15 Binary files /dev/null and b/api-samples/windows/arrow_in.png differ diff --git a/api-samples/windows/background.js b/api-samples/windows/background.js new file mode 100644 index 00000000..c97232e5 --- /dev/null +++ b/api-samples/windows/background.js @@ -0,0 +1,30 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +async function start() { + const current = await chrome.windows.getCurrent(); + + const allTabs = await chrome.tabs.query({}); + allTabs.forEach((tab) => { + if (tab.windowId != current.id) { + chrome.tabs.move(tab.id, { + windowId: current.id, + index: tab.index + }); + } + }); +} + +// Set up a click handler so that we can merge all the windows. +chrome.action.onClicked.addListener(start); diff --git a/api-samples/windows/manifest.json b/api-samples/windows/manifest.json new file mode 100644 index 00000000..6427c3be --- /dev/null +++ b/api-samples/windows/manifest.json @@ -0,0 +1,17 @@ +{ + "name": "Merge Windows", + "version": "1.0.3", + "description": "Merges all of the browser's windows into the current window", + "icons": { + "48": "merge_windows_48.png", + "128": "merge_windows_128.png" + }, + "background": { + "service_worker": "background.js" + }, + "action": { + "default_icon": "arrow_in.png", + "default_title": "Merge Windows" + }, + "manifest_version": 3 +} diff --git a/api-samples/windows/merge_windows_128.png b/api-samples/windows/merge_windows_128.png new file mode 100644 index 00000000..a37b6065 Binary files /dev/null and b/api-samples/windows/merge_windows_128.png differ diff --git a/api-samples/windows/merge_windows_48.png b/api-samples/windows/merge_windows_48.png new file mode 100644 index 00000000..3542c6a4 Binary files /dev/null and b/api-samples/windows/merge_windows_48.png differ