Created
May 7, 2013 22:27
-
-
Save jorilallo/5536679 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var downloads = []; | |
var downloadSong = function(url, tabid){ | |
if( chrome.webRequest.onBeforeRequest.hasListeners() ) | |
chrome.webRequest.onBeforeRequest.removeListener(findmp3); | |
chrome.tabs.sendMessage( tabid , {action: "getSong", url : url} ); | |
setTimeout(function(){ startListener(); },500) | |
} | |
var findmp3 = function(details){ | |
if( details.url.indexOf("cloudfront.net/mp3/") === -1 && downloads.indexOf(details.url) ) return; | |
downloadSong(details.url, details.tabId) | |
}; | |
var startListener = function(){ | |
chrome.webRequest.onBeforeRequest.addListener( | |
findmp3, | |
{urls: ["*://*.cloudfront.net/mp3/*"]}, | |
['blocking'] | |
); | |
}; | |
startListener(); |
This file contains hidden or 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.onMessage.addListener(function(request, sender, sendResponse) { | |
if (request.action == "getSong"){ | |
var title = document.title; | |
if( title === 'Spotify Web Player' ) return; | |
title = title.replace("- Spotify",""); | |
var a = document.createElement('a'); | |
a.download = title + '.mp3'; | |
a.href = request.url; | |
a.dataset.downloadurl = ['audio/mpeg', a.download, a.href].join(':'); | |
a.click(); | |
}else{ | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment