Use tab-change event handler

jh-changes
Daniel Campoverde 7 years ago
parent e9a7f679c4
commit 3acd921d52
  1. 16
      src/background/tabs.js

@ -1,5 +1,13 @@
let prevSelTab = 0;
let currSelTab = 2;
let prevSelTab = 1;
let currSelTab = 1;
browser.tabs.onActivated.addListener(tabChangeHandler);
function tabChangeHandler(activeInfo) {
prevSelTab = currSelTab;
currSelTab = activeInfo.tabId;
console.log("prev tab: " + prevSelTab + " - curr tab: " + currSelTab);
}
const closeTab = (id) => {
return browser.tabs.remove(id);
@ -71,6 +79,7 @@ const selectPrevTab = (current, count) => {
}
let select = (current - count + tabs.length) % tabs.length;
let id = tabs[select].id;
currSelTab = id;
return browser.tabs.update(id, { active: true });
});
};
@ -86,6 +95,7 @@ const selectNextTab = (current, count) => {
}
let select = (current + count) % tabs.length;
let id = tabs[select].id;
currSelTab = id;
return browser.tabs.update(id, { active: true });
});
};
@ -97,6 +107,7 @@ const selectFirstTab = () => {
return browser.tabs.query({ currentWindow: true }).then((tabs) => {
let id = tabs[0].id;
currSelTab = id;
return browser.tabs.update(id, { active: true });
});
};
@ -108,6 +119,7 @@ const selectLastTab = () => {
return browser.tabs.query({ currentWindow: true }).then((tabs) => {
let id = tabs[tabs.length - 1].id;
currSelTab = id;
return browser.tabs.update(id, { active: true });
});
};