implement simple tab switch

This commit is contained in:
Shin'ya Ueoka 2017-08-12 12:55:37 +09:00
parent f1d4bb8c37
commit 8e5ceebf61
3 changed files with 46 additions and 6 deletions

23
src/background/tabs.js Normal file
View 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 };