Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removing api listener for onRemove and fixing the way tabs are remove…

…d from array
  • Loading branch information...
commit e948891369f461cdf16dfc2af8457b8afcc8bfe0 1 parent de97bd0
@jgv authored
Showing with 19 additions and 24 deletions.
  1. +19 −24 tabby.js
View
43 tabby.js
@@ -1,5 +1,5 @@
var tabs = [];
-var timeout = 900; // fifteen minutes... this seems to go by really quick though
+var timeout = 30; // fifteen minutes... this seems to go by really quick though
var timerId, selected;
function tabWasCreated (tabId, changeInfo, tab) {
@@ -14,22 +14,10 @@ function tabWasUpdated (tabId, changeInfo, tab) {
}
}
-function tabWasRemoved (tabId, removeInfo) {
- for (i = 0; i < tabs.length; i++) {
- if (tabs[i].id === tabId.id) {
- tabs.splice(tabs.indexOf(tabs[i]), 1);
- }
- }
-}
-
-function tabIsSelected(id) {
+function tabIsSelected (id) {
selected = id;
}
-//function tabIsVideo(tab) {
-
-//}
-
function Tab (tabId, changeInfo, tab) {
this.id = tabId.id;
this.counter = 0;
@@ -37,28 +25,35 @@ function Tab (tabId, changeInfo, tab) {
timer(this.id);
}
-function timer(id) {
+function timer (id) {
timerId = setInterval(checkTabs, 2000); // playing with the timer interval for performance
}
-function stopTimer(timerId) {
+function stopTimer (timerId) {
clearInterval(timerId);
}
+function killTab (tab, timerId) {
+ console.log(tabs);
+ console.log(tab);
+ chrome.tabs.remove(tab.id);
+ stopTimer(timerId);
+ tabs.splice(tabs.indexOf(tab, 1));
+ console.log(tabs);
+}
+
function checkTabs () {
- for (i = 0; i < tabs.length; i++) {
+ for (i = 0; i < tabs.length; i++) {
if (tabs[i].id != selected) {
- tabs[i].counter = tabs[i].counter + 1;
+ tabs[i].counter++;
}
- if (tabs[i].counter >= timeout) {
- chrome.tabs.remove(tabs[i].id);
- tabs.splice(tabs.indexOf(tabs[i]), 1);
- stopTimer(timerId);
+ if (tabs[i].counter >= timeout) {
+ killTab(tabs[i], timerId);
}
+ // console.log(tabs[i].id + ': ' + tabs[i].counter);
}
}
chrome.tabs.onCreated.addListener(tabWasCreated);
chrome.tabs.onUpdated.addListener(tabWasUpdated);
-chrome.tabs.onSelectionChanged.addListener(tabIsSelected);
-chrome.tabs.onRemoved.addListener(tabWasRemoved);
+chrome.tabs.onSelectionChanged.addListener(tabIsSelected);
Please sign in to comment.
Something went wrong with that request. Please try again.