Advertisement
Guest User

Download mp3 vk.com

a guest
May 27th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Download mp3 vk.com
  3. // @include     https://vk.com/*
  4. // @include     http://vk.com/*
  5. // @grant       GM_xmlhttpRequest
  6. // ==/UserScript==
  7. var parseExt=S=>(S=/^[^?]+([.]\w+)[?]/.exec(S))? S[1]: '.mp3',
  8. Save = (Url, Name, isOK)=>{
  9.   if(!Url || !Name || !isOK) return;
  10.   var A;
  11.   (A = document.createElement('A')).href = Url;
  12.   A.download = Name.replace(/[^а-я\x21-\x7e\s\w]/gi,"-").replace(/[\/\\\:\*\?"<>\|\&]+/g, "-");
  13.   document.body.appendChild(A).click(); document.body.removeChild(A);
  14. },
  15. GetFromServer = (link, name)=>GM_xmlhttpRequest({
  16.     method: "GET",
  17.     responseType: 'blob',
  18.     overrideMimeType: 'text/plain; charset=x-user-defined',
  19.     url: link,
  20.     onload: R=>Save(window.URL.createObjectURL(R.response), name, R.status==200)
  21. });
  22. window.addEventListener('contextmenu', e=>{
  23.   if (!e.ctrlKey) return; e.preventDefault();
  24.   var link, info, a = e.target;
  25.   while (!a.classList.contains('audio') && (a=a.parentNode)) if(a==document.body) return;
  26.   link = a.querySelector('[id^="audio_info"]').value;
  27.   info = a.getElementsByClassName('title_wrap')[0];
  28.   GetFromServer(link, info.textContent.trim() + parseExt(link));
  29. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement