// ==UserScript== // @name VKget music // @version 1.1 // @description Скрипт добавляет ссылки для скачивания к аудиозаписям на vk.com. Для сохранения всех файлов через wget нажмите F2. // This script adds download links to audios at vk.com. 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 // 25.08.2017 // @namespace https://greasyfork.org/users/148414 // @downloadURL none // ==/UserScript== (function() { function decode_url(url){ var tmp = {}; AudioPlayerHTML5.prototype._setAudioNodeUrl(tmp, url); return tmp.src; } 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() { run = 1; var audio_row_selector = '.audio_row'; if ($(audio_row_selector).length <= ready) { run = 0; return; } var $this = $($(audio_row_selector)[ready]); 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) { s_response = response.split('"'); //alert("s_response: " + s_response); if (s_response.length > 1) { link = decode_url(s_response[1]); //alert("link: " + link); if (link != s_response[1]) { var link_style = 'position: absolute; right: -12px; top: 12px; color: white; z-index: 100; background: red; border-radius: 3px 3px 3px 3px; padding: 2px 6px; font-size: 16px; opacity: 0.5;'; 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; $this.append('' ); ready++; wget_list += 'wget -c -O "' + track_name + '.mp3" ' + link + escape('\n'); } } else { if (response.match(/!bool/)) { //alert("skip bad link"); ready++; } } } }); setTimeout( function(){ add_download_links() }, 500); } add_download_links(); if (!ready) setTimeout( function(){ add_download_links() }, 2000); window.addEventListener("scroll", function(){ if (!run) add_download_links(); }, false); $('body').keydown(function(e){ if (e.which == 113) { // F2 download(wget_list, 'wget.sh', 'text/plain'); } }); })();