diff --git a/tutorials/tabs-manager/images/icon-128.png b/tutorials/tabs-manager/images/icon-128.png new file mode 100644 index 00000000..94c9f79a Binary files /dev/null and b/tutorials/tabs-manager/images/icon-128.png differ diff --git a/tutorials/tabs-manager/images/icon-16.png b/tutorials/tabs-manager/images/icon-16.png new file mode 100644 index 00000000..58774f45 Binary files /dev/null and b/tutorials/tabs-manager/images/icon-16.png differ diff --git a/tutorials/tabs-manager/images/icon-32.png b/tutorials/tabs-manager/images/icon-32.png new file mode 100644 index 00000000..51fc548a Binary files /dev/null and b/tutorials/tabs-manager/images/icon-32.png differ diff --git a/tutorials/tabs-manager/images/icon-48.png b/tutorials/tabs-manager/images/icon-48.png new file mode 100644 index 00000000..cf0bbc3d Binary files /dev/null and b/tutorials/tabs-manager/images/icon-48.png differ diff --git a/tutorials/tabs-manager/manifest.json b/tutorials/tabs-manager/manifest.json new file mode 100644 index 00000000..0ae8a6c9 --- /dev/null +++ b/tutorials/tabs-manager/manifest.json @@ -0,0 +1,20 @@ +{ + "manifest_version": 3, + "name": "Tab Manager for Google Dev Docs", + "version": "1.0", + "icons": { + "16": "images/icon-16.png", + "32": "images/icon-32.png", + "48": "images/icon-48.png", + "128": "images/icon-128.png" + }, + "action": { + "default_popup": "popup.html" + }, + "host_permissions": [ + "https://developer.chrome.com/*" + ], + "permissions": [ + "tabGroups" + ] +} diff --git a/tutorials/tabs-manager/popup.css b/tutorials/tabs-manager/popup.css new file mode 100644 index 00000000..05ad0938 --- /dev/null +++ b/tutorials/tabs-manager/popup.css @@ -0,0 +1,40 @@ +/* +Copyright 2022 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. +*/ + +body { + width: 20rem; +} + +ul { + list-style-type: none; + padding-inline-start: 0; + margin: 1rem 0; +} + +li { + padding: 0.25rem; +} +li:nth-child(odd) { + background: #80808030; +} +li:nth-child(even) { + background: #ffffff; +} + +h3, +p { + margin: 0; +} diff --git a/tutorials/tabs-manager/popup.html b/tutorials/tabs-manager/popup.html new file mode 100644 index 00000000..6d50dc02 --- /dev/null +++ b/tutorials/tabs-manager/popup.html @@ -0,0 +1,25 @@ + + + + + + + + + + + +

Google Dev Docs

+ + + + + + diff --git a/tutorials/tabs-manager/popup.js b/tutorials/tabs-manager/popup.js new file mode 100644 index 00000000..794a5094 --- /dev/null +++ b/tutorials/tabs-manager/popup.js @@ -0,0 +1,50 @@ +// Copyright 2022 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. + +const tabs = await chrome.tabs.query({ + url: [ + "https://developer.chrome.com/docs/webstore/*", + "https://developer.chrome.com/docs/extensions/*", + ], +}); + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator +const collator = new Intl.Collator(); +tabs.sort((a, b) => collator.compare(a.title, b.title)); + +const template = document.getElementById("li_template"); +const elements = new Set(); +for (const tab of tabs) { + const element = template.content.firstElementChild.cloneNode(true); + + const title = tab.title.split("-")[0].trim(); + const pathname = new URL(tab.url).pathname.slice("/docs".length); + + element.querySelector(".title").textContent = title; + element.querySelector(".pathname").textContent = pathname; + element.querySelector("a").addEventListener("click", async () => { + // need to focus window as well as activate tab + await chrome.windows.update(tab.windowId, { focused: true }); + await chrome.tabs.update(tab.id, { active: true }); + }); + + elements.add(element); +} +document.querySelector("ul").append(...elements); + +const button = document.querySelector("button"); +button.addEventListener("click", async () => { + const group = await chrome.tabs.group({ tabIds: tabs.map(({ id }) => id) }); + await chrome.tabGroups.update(group, { title: "DOCS" }); +});