Last active
July 26, 2018 06:07
-
-
Save sapphiriq/3920047 to your computer and use it in GitHub Desktop.
TracksFlow download track (http://cl.ly/image/3h3Z0H2m0t2w)
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
// ==UserScript== | |
// @name TracksFlow Download | |
// @namespace https://github.com/sapphiriq/ | |
// @description Tracksflow content downloader | |
// @author Alexander Khorin <sapphiriq@gmail.com> | |
// @copyright Alexander Khorin, 2012-2013 | |
// @include http://tracksflow.com/* | |
// ==/UserScript== | |
(function () { | |
if (!(unsafeWindow && unsafeWindow.player)) { | |
var unsafeWindow = (function() { | |
var div = document.createElement('div'); | |
div.setAttribute('onclick', 'return window;'); | |
return div.onclick(); | |
})(); | |
} | |
// Helpers | |
// ======================================================== | |
var downloadLinkAs = function (link, name) { | |
var a = document.createElement('a'); | |
a.target = '_blank'; | |
a.href = link; | |
a.download = name; | |
a.downloadurl = link; | |
a.click(); | |
} | |
var download = function (track) { | |
track = track || player.getCurrentTrack(); | |
if (!track) return alert('no track'); | |
player.getLink(track, { | |
success: function (track) { | |
var link = track.getUrl(); | |
downloadLinkAs(link, getTitle(track) + '.mp3'); | |
} | |
}); | |
} | |
var getTitle = function (track) { | |
return track.getArtist() + ' - ' + track.getName(); | |
} | |
// Shortcuts | |
// ======================================================== | |
var window = unsafeWindow; | |
var $ = window.$; | |
var player = window.player; | |
// Create button | |
// ======================================================== | |
var popupView = window.classes.view.socialButtonsView; | |
var tmpl = $('#socialButtons-template'); | |
var downloadHtml = '<li class="js-download">\ | |
<div class="text-with-icon text-with-icon-mdlm">\ | |
<div class="icon c-green-ifcheck-svg check down-arrow-icon">\ | |
<svg viewBox="0 0 512 512">\ | |
<g id="filter">\ | |
<rect width="512" height="512"></rect>\ | |
</g>\ | |
</svg>\ | |
</div>\ | |
<div class="text" style="color:#A4CF65">Download</div>\ | |
</div>\ | |
</li>'; | |
tmpl.html( tmpl.html() + downloadHtml); | |
popupView.prototype.events['click .js-download'] = 'downloadTrack'; | |
popupView.prototype.downloadTrack = function() { | |
var id, track; | |
id = this.model.getSyncLocalId(); | |
track = player.get('collection').findTrackByLocalId(id) | |
download(track); | |
}; | |
})(); |
Cool nice work! Can't wait to try the playlist download.
11 months ago 'soon'. any progress? :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, created a little fork with playlist download feature ;)
https://gist.github.com/4539178