Created
May 24, 2011 22:40
-
-
Save buzzedword/989918 to your computer and use it in GitHub Desktop.
Grooveshark Chrome Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.extension.onRequest.addListener( | |
function(request, sender, sendResponse) { | |
switch (request.message.action){ | |
case "addSong" : | |
Grooveshark.addSongsByID(request.message.ID, true); | |
break; | |
case "getSong" : | |
var song = GrooveShark.getCurrentSongStatus().song; | |
sendResponse({"songTitle": song}); | |
break; | |
} | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Buzzedword Extension", | |
"version": "1.0", | |
"description": "Demo", | |
"icons":{ | |
"128":"icon_128.png" | |
}, | |
"browser_action": { | |
"default_icon": "icon.png", | |
"popup": "empty.html" | |
}, | |
"permissions": ["tabs", "http://grooveshark.com/*"], | |
"content_scripts": [ | |
{ | |
"matches": ["http://grooveshark.com/*"], | |
"js": ["gs.js"], | |
"run_at": "document_end" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GetChromeDomain(url){ | |
var parts, domainSplit, name; | |
parts = url.split('/'); | |
domainSplit = parts[2].split(':'); | |
name = domainSplit[0]; | |
return name; | |
} | |
function startGS(tabID){ | |
chrome.tabs.sendRequest(tabID, { | |
message : { | |
action : "addSong", | |
ID : "28102067" | |
} | |
}); | |
} | |
chrome.windows.getCurrent( function(Window){ | |
chrome.tabs.getAllInWindow(Window.id, function(tabs){ | |
var gsTab; | |
for (var i in tabs){ | |
if (GetChromeDomain(tabs[i].url) == 'grooveshark.com'){ | |
gsTab = tabs[i].id; | |
} | |
} | |
if (typeof gsTab != 'undefined'){ | |
startGS(gsTab); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment