-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
executable file
·34 lines (32 loc) · 934 Bytes
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
// https://developer.chrome.com/docs/extensions/reference/api/commands?hl=zh-cn
chrome.commands.onCommand.addListener((cmd) => {
console.log(cmd)
switch (cmd) {
case "close_other_tabs":
chrome.tabs.query({
'active': false,
'pinned': false
}, tabs => chrome.tabs.remove(tabs.map(tab => tab.id)))
break
case "copy_this_tab":
chrome.tabs.query({
'active': true,
'currentWindow': true
},
tabs => chrome.tabs.duplicate(tabs[0].id))
break
case "lock_this_tab":
chrome.tabs.query({
'active': true,
'currentWindow': true
},
tabs => chrome.tabs.update(tabs[0].id, {
pinned: !tabs[0].pinned
}))
break
}
})