implement simple tab switch
This commit is contained in:
parent
f1d4bb8c37
commit
8e5ceebf61
3 changed files with 46 additions and 6 deletions
23
src/background/tabs.js
Normal file
23
src/background/tabs.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
const selectPrevTab = (current) => {
|
||||
chrome.tabs.query({ currentWindow: true }, (tabs) => {
|
||||
if (tabs.length < 2) {
|
||||
return;
|
||||
}
|
||||
let select = (current - 1) % tabs.length
|
||||
let id = tabs[select].id;
|
||||
chrome.tabs.update(id, { active: true })
|
||||
});
|
||||
};
|
||||
|
||||
const selectNextTab = (current) => {
|
||||
chrome.tabs.query({ currentWindow: true }, (tabs) => {
|
||||
if (tabs.length < 2) {
|
||||
return;
|
||||
}
|
||||
let select = (current + 1 + tabs.length) % tabs.length
|
||||
let id = tabs[select].id;
|
||||
chrome.tabs.update(id, { active: true })
|
||||
});
|
||||
};
|
||||
|
||||
export { selectNextTab, selectPrevTab };
|
Reference in a new issue