// ==UserScript==
// @name VKget music
// @version 1.0
// @description Скрипт добавляет ссылки для скачивания к аудиозаписям на vk.com. Если ссылки не появились автоматически, нажмите F9. Для сохранения всех файлов через wget нажмите F2.
// This script adds download links to audios at vk.com. If links did not appear automatically press F9. To save all files via wget, press F2.
// @match *://vk.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @grant none
// @run-at document-idle
// 12.08.2017
// @namespace http://greasyfork.icu/users/148414
// ==/UserScript==
(function() {
function extra(t) {
if (~t.indexOf("audio_api_unavailable")) {
var i = t.split("?extra=")[1].split("#")
, e = o(i[1]);
if (i = o(i[0]),
!e || !i)
return t;
e = e.split(String.fromCharCode(9));
for (var a, r, l = e.length; l--; ) {
if (r = e[l].split(String.fromCharCode(11)),
a = r.splice(0, 1, i)[0],
!s[a])
return t;
i = s[a].apply(null, r)
}
if (i && "http" === i.substr(0, 4))
return i
}
return t
}
function o(t) {
if (!t || t.length % 4 == 1)
return !1;
for (var i, e, o = 0, s = 0, r = ""; e = t.charAt(s++); )
e = a.indexOf(e),
~e && (i = o % 4 ? 64 * i + e : e,
o++ % 4) && (r += String.fromCharCode(255 & i >> (-2 * o & 6)));
return r
}
var a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN0PQRSTUVWXYZO123456789+/="
, s = {
v: function(t) {
return t.split("").reverse().join("")
},
r: function(t, i) {
t = t.split("");
for (var e, o = a + a, s = t.length; s--; )
e = o.indexOf(t[s]),
~e && (t[s] = o.substr(e - i, 1));
return t.join("")
},
x: function(t, i) {
var e = [];
return i = i.charCodeAt(0),
t.split("").forEach(function(o) {
e.push(String.fromCharCode(o.charCodeAt(0) ^ i))
}),
e.join("")
}
}
function download(strData, strFileName, strMimeType) {
var D = document,
A = arguments,
a = D.createElement("a"),
d = A[0],
n = A[1],
t = A[2] || "text/plain";
a.href = "data:" + strMimeType + "charset=utf-8," + strData;
if (window.MSBlobBuilder) { // IE10
var bb = new MSBlobBuilder();
bb.append(strData);
return navigator.msSaveBlob(bb, strFileName);
}
if ('download' in a) { //FF20, CH19
a.setAttribute("download", n);
a.innerHTML = "downloading...";
D.body.appendChild(a);
setTimeout(function() {
var e = D.createEvent("MouseEvents");
e.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
D.body.removeChild(a);
}, 66);
return true;
};
}
var ready = 0;
var wget_list = "";
var run = 0;
function add_download_links() {
var audio_row_selector = '.audio_row';
var link_style = 'position: absolute; right: -16px; top: 17px; color: white; z-index: 100; background: red; border-radius: 3px 0 0 3px; padding: 0px 2px; font-size: 16px; opacity: 0.5;';
run = 1;
if ($(audio_row_selector).length <= ready) {
run = 0;
return;
}
var $this = $($(audio_row_selector)[ready]);
var song_name = $this.find('.audio_row__title_inner').text().trim().replace(/\"/g, '\'');
var performer_name = $this.find('.audio_row__performer').text().trim().replace(/\"/g, '\'');
var track_name = performer_name + ' - ' + song_name;
var audio_id_raw = $this.data('audio');
var audio_id = audio_id_raw[1] + '_' + audio_id_raw[0];
var link = "";
$.ajax({
url: 'https://vk.com/al_audio.php',
method: 'post',
async: false,
data: {
act: 'reload_audio',
al: 1,
ids: audio_id
},
success: function(response) {
var matches = response.match(/(https:\\\/\\\/.+\.mp3)/);
if (matches) {
s_response = response.split('"');
link = extra(s_response[1]);
if (link != s_response[1]) {
$this.append('<a class="audio-download-link" style="' + link_style +
'" title="Скачать" download="' +
track_name + '.mp3" data-track_name="' +
track_name + '" href="' + link +
'" onclick="arguments[0].stopPropagation()">♫</a>'
);
ready++;
wget_list += 'wget -c -O "' + track_name + '.mp3" ' + link + escape('\n');
}
}
}
});
setTimeout( function(){ add_download_links() }, 500);
}
add_download_links();
if (!ready)
setTimeout( function(){ add_download_links() }, 2000);
$('body').keydown(function(e){
if (!run && e.which == 120) { // F9
add_download_links();
}
if (e.which == 113) { // F2
download(wget_list, 'wget.sh', 'text/plain');
}
});
})();