Skip to content

Commit

Permalink
NEW FEATURES!! Now supports leaving the player paused and not having …
Browse files Browse the repository at this point in the history
…youtube start it if it was already paused. Also supports start again if the youtube tab is closed or gone away. Changed how youtube sends request it now uses events
  • Loading branch information
Marco Munizaga committed Jun 25, 2011
1 parent 355221d commit 07f36e2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 25 deletions.
32 changes: 25 additions & 7 deletions js/bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ console.log("it lives LOL");
tabs = 1;
gsUrl = "grooveshark.com";
gsTab=0;
isGSPaused = true;
currentTab = 0;


function releaseTheShark(){
chrome.tabs.executeScript(gsTab, {'file':'js/injectShark.js'});
}
Expand Down Expand Up @@ -29,6 +33,9 @@ chrome.extension.onRequest.addListener(
"from a content script:" + sender.tab.url + ' and the tab info is ' + sender.tab :
"from the extension");
console.log('sender tab id is ', sender.tab.id);

chrome.tabs.getSelected(null, function(tab) { currentTab=tab.id; });

if (request.gsTab == 'findMePlz'){
console.log('finding the shark, plz hold')
intervalId=setInterval(findId, 100);
Expand All @@ -37,19 +44,30 @@ chrome.extension.onRequest.addListener(

if (request.gsTab == 'findActive'){
gsTab = sender.tab.id;
//clear the isGSPaused boolean
if(currentTab == gsTab){
isGSPaused = false;
}
console.log('Active GS is ', gsTab);
}

if (gsTab==0){
console.log('GS has not been opened');
}
if (request.command == "resumeShark"){
chrome.tabs.sendRequest(gsTab, {command: "resumeShark"});
sendResponse({});
if (request.gsTab == 'isGSPaused'){
//if the sender of the request and the
if(currentTab == gsTab){
isGSPaused = true;
}
}
if (!isGSPaused && request.command == "resumeShark"){
chrome.tabs.sendRequest(gsTab, {command: "resumeShark"});
sendResponse({});
}else if ( request.command == "pauseShark"){
chrome.tabs.sendRequest(gsTab, {command: "pauseShark"});
sendResponse({});
chrome.tabs.sendRequest(gsTab, {command: "pauseShark"});
sendResponse({});
}else{
sendResponse({}); // snub them.
console.log(request);
sendResponse({}); // snub them.
console.log(request);
}
});
6 changes: 5 additions & 1 deletion js/injectShark.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ function findActiveGS(){
chrome.extension.sendRequest({'gsTab':'findActive'});
}

function tellbgGSPaused(){
chrome.extension.sendRequest({'gsTab':'isGSPaused'});
}

window.addEventListener("playing", function(){console.log('playing'); findActiveGS();}, false, true);
window.addEventListener("paused", function(){console.log('paused');}, false, true);
window.addEventListener("paused", function(){console.log('paused'); tellbgGSPaused();}, false, true);

chrome.extension.onRequest.addListener(recRequest);

Expand Down
46 changes: 29 additions & 17 deletions js/injectTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,45 @@ function realMain(){

function main(){
window.youDidSomething = function(state){
//console.log('youDidSomething' + state);
playing = document.getElementById('playing');
playing.innerText= state;
:
if (state == 2){
var resumeShark = document.createEvent("Events");
resumeShark.initEvent("resumeShark",true,false);
document.dispatchEvent(resumeShark);
}
if (state == 1){
var pauseShark = document.createEvent("Events");
pauseShark.initEvent("pauseShark",true,false);
document.dispatchEvent(pauseShark);
}
}

window.onunload = function(){
var resumeShark = document.createEvent("Events");
resumeShark.initEvent("resumeShark",true,false);
document.dispatchEvent(resumeShark);
}

}

//this gets the element status (status describes whether the video is playing) within the page
function getSt(){
playing = document.getElementById('playing');
//console.log('getSt: ' + playing.innerText);
doWhat(parseInt(playing.innerText));
}

addlist();
setInterval(getSt, 500);

var playStatus = document.createElement('div');
playStatus.id = "playing";
playStatus.innerText='lol';


function inject(main){
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ main +')();'));
(document.body || document.head || document.documentElement).appendChild(script);
}

(document.body || document.head || document.documentElement).appendChild(playStatus);
function listenForChange(){
window.addEventListener("pauseShark", function(){console.log('pausing Grooveshark'); rememberToPause();}, false, true);
window.addEventListener("resumeShark", function(){console.log('playing Grooveshark'); rememberToPlay();}, false, true);
}

addlist();
listenForChange();
inject(main);

var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ main +')();'));
(document.body || document.head || document.documentElement).appendChild(script);
}

0 comments on commit 07f36e2

Please sign in to comment.