Skip to content

Commit

Permalink
checking if user is on a youtube page for watching video
Browse files Browse the repository at this point in the history
  • Loading branch information
jgv committed May 24, 2011
1 parent cb53b15 commit c71f642
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
5 changes: 5 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
"background_page" : "background.html",
"permissions" : [ "tabs" ],
"options_page" : "options.html"
//"content_scripts" : [
// {
// "js" : ["youtube.js"]
// }
//]
}
39 changes: 17 additions & 22 deletions tabby.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@ var timerId, selected;
var timeout = localStorage["time_out"] * 60 || 600; // default to ten minutes
//var timeout = 20; // 'dev mode'


function youTube (tab) {
ytplayer = document.getElementById("watch-player");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
function onytplayerStateChange (newState) {
if (newState === 'stopped') { // pseduo code
tabs.splice(tabs.indexOf(tab, 1));
// kill the tab
}
}
}

function Tab (tabId, changeInfo, tab) {
this.id = tabId.id;
function Tab (tab) {
this.id = tab.id;
this.counter = 0;
this.video = /youtube.com\/watch/.test(tab.url) ? true : false;
tabs.push(this);
timer(this.id);
}
Expand All @@ -33,15 +22,18 @@ function stopTimer (timerId) {
function killTab (tab, timerId) {
chrome.tabs.remove(tab.id, function (){
stopTimer(timerId);
tabs.splice(tabs.indexOf(tab), 1);
tabs.splice(tabs.indexOf(tab), 1);
})(tab,timerId);
}

function checkTabs () {
//chrome.tabs.getAllInWindow(null, function (tabArray){
//for (i = 0; i <= tabArray.length; i++){
//chrome.tabs.sendRequest(tabArray[i])
//}
//});
for (i = 0; i < tabs.length; i++) {
if (tabs[i].id != selected) {
tabs[i].counter = tabs[i].counter + 2; // bc the timeout is at 2 seconds
}
tabs[i].counter = (tabs[i].id === selected) ? tabs[i].counter : tabs[i].counter + 2;
if (tabs[i].counter >= timeout) {
killTab(tabs[i], timerId);
}
Expand All @@ -50,19 +42,22 @@ function checkTabs () {
}

// Chrome API interacitons
chrome.tabs.onCreated.addListener(function (tabId, changeInfo, tab) {
new Tab(tabId, changeInfo, tab);
chrome.tabs.onCreated.addListener(function (tab) {
new Tab(tab);
});

chrome.tabs.onRemoved.addListener(function (tab) {
chrome.tabs.remove(tab.id);
tabs.splice(tabs.indexOf(tab), 1);
tabs.splice(tabs.indexOf(tab), 1);
});

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
for (n = 0; n < tabs.length; n++) {
if (tabs[n].id === tabId) {
tabs[n].counter = 0;
tabs[n].counter = 0;
if (changeInfo.status === "loading" || "complete") {
tabs[n].video = /youtube.com\/watch/.test(tab.url) ? true : false;
}
}
}
});
Expand Down

0 comments on commit c71f642

Please sign in to comment.