
谷歌浏览器插件教程官方例子之管理标签页
编译工具 / 发布于 3个月前 / 更新于 3个月前 / 本文字数: 2.71k 字 /教程集数: 18
标签: Manage tabs / Chrome 插件例子
Manage tabs 管理标签页
建立您的第一个选项卡管理器。
- 使用到了
Action API
- 使用到了 Tabs API.
- 使用到了 TabGroups API
manifest.json
{
"manifest_version": 3,
"name": "Tab Manager for Chrome 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"
]
}
popup.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./css/popup.css" />
</head>
<body>
<template id="li_template">
<li>
<a>
<h3 class="title">Tab Title</h3>
<p class="pathname">Tab Pathname</p>
</a>
</li>
</template>
<h1>Google Dev Docs</h1>
<button>Group Tabs</button>
<ul></ul>
<script src="./popup.js" type="module"></script>
</body>
</html>
popup.js
const tabs = await chrome.tabs.query({
url: [
"https://developer.chrome.com/docs/webstore/*",
"https://developer.chrome.com/docs/extensions/*",
],
});
console.log('tabs',tabs)
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 the active tab
await chrome.tabs.update(tab.id, { active: true });
await chrome.windows.update(tab.windowId, { focused: true });
});
elements.add(element);
}
document.querySelector("ul").append(...elements);
const button = document.querySelector("button");
button.addEventListener("click", async () => {
const tabIds = tabs.map(({ id }) => id);
const group = await chrome.tabs.group({ tabIds });
await chrome.tabGroups.update(group, { title: "DOCS" });
});
chrome.tabs.update(tab.id, { active: true }); 更新标签也为选中
chrome.windows.update(tab.windowId, { focused: true });
版权提示
1.除了标识原创之外,其他可能来源于网友的分享,仅供学习使用2.如您发现侵犯了您的权利,请联系我们删除
3.转载必须带本文链接,否则你将侵权
4.关于会员或其发布的相关内容均由会员自行提供,会员依法应对其提供的任何信息承担全部责任,本站不对此承担任何法律责任
0 人点赞
评论区 (0)
最新视频教程
-
-
黑白课堂
- Laravel6 全套入门实战
- 4651 2
-
-
-
黑白课堂
- Laravel6 全套入门实战
- 4572 5
-
-
-
黑白课堂
- Laravel6 全套入门实战
- 4457 0
-
-
-
黑白课堂
- Laravel6 全套入门实战
- 4077 0
-
-
-
黑白课堂
- Laravel6 全套入门实战
- 4079 0
-
最新视频课程
-
Laravel 消息通知使用
黑白课堂
285523 03年前
-
ace.js 打造一款属于你的 Web 编辑器,入门文档。
黑白课堂
15296 04年前
-
Laravel 实现 RBAC 权限管理功能 Permission 包操作
黑白课堂
14136 05年前
-
微信小程序等比例图片压缩上传,100%可用,非官方压缩方法
黑白课堂
12180 14年前
-
宝塔面板强制绑定账号修改为不强制绑定方案
黑白课堂
11366 03年前
-
wap2App 入门讲解,100%速成,全面为你讲解。
黑白课堂
9211 04年前
-
Laravel 设置请求头 header 参数
黑白课堂
8328 03年前
-
Laravel 的 PhpSpreadsheet 包入门
黑白课堂
8325 04年前
-
Laravel 表格操作 Maatwebsite/Laravel-Excel 3.1 最新版本的操作指南
黑白课堂
8297 04年前
-
Linux 下如何监听我们的脚本是否掉线了
黑白课堂
7565 03年前
-
KongQi Laravel Admin2.0 文档安装
黑白课堂
3914 23年前
-
KongQi Laravel admin2.0 layui admin 版本序言
黑白课堂
3342 03年前
-
易语言入门拖入文件导入到超级列表框表格内
哪吒
8406 13年前
-
易语言入门易语言定时任务模块
哪吒
6491 03年前
-
postman 使用手册cookie 使用
哪吒
4975 03年前
-
谷歌浏览器插件教程proxy 代理
哪吒
4534 01年前
-
易语言入门判断文件夹是否存在的方法
哪吒
4255 02年前
-
易语言入门TAB 标签页制作
哪吒
4204 03年前
-
Visual Studio Code 入门和使用教程插件安装使用
哪吒
4135 13年前
-
Visual Studio Code 入门和使用教程安装下载
哪吒
4105 03年前
