Skip to content

Instantly share code, notes, and snippets.

@buzzedword
Created May 24, 2011 22:40
Show Gist options
  • Save buzzedword/989918 to your computer and use it in GitHub Desktop.
Save buzzedword/989918 to your computer and use it in GitHub Desktop.
Grooveshark Chrome Extension
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;
}
}
);
{
"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"
}
]
}
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