mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-03-26 13:19:49 +07:00
Windows api mv3 sample (#959)
* WIP windows API sample * Update background.js * Added mv3 windows API sample * Corrections based on review
This commit is contained in:
committed by
GitHub
parent
cd11c730ea
commit
2527b666a6
14
api-samples/windows/README.md
Normal file
14
api-samples/windows/README.md
Normal file
@@ -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.
|
||||
BIN
api-samples/windows/arrow_in.png
Normal file
BIN
api-samples/windows/arrow_in.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 594 B |
30
api-samples/windows/background.js
Normal file
30
api-samples/windows/background.js
Normal file
@@ -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);
|
||||
17
api-samples/windows/manifest.json
Normal file
17
api-samples/windows/manifest.json
Normal file
@@ -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
|
||||
}
|
||||
BIN
api-samples/windows/merge_windows_128.png
Normal file
BIN
api-samples/windows/merge_windows_128.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
BIN
api-samples/windows/merge_windows_48.png
Normal file
BIN
api-samples/windows/merge_windows_48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
Reference in New Issue
Block a user